• Hello! Tell lplease, is it possible to set a condition?
    Ex.: if product have options I want to show picture in poducts catalog, if no – picture don;t show.
    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Pektsekye

    (@pektsekye)

    Hello,

    You can use this code.

    To check if product has options:

    
      $hasOptions = false;
      if (function_exists('Pektsekye_PO')){
        include_once(Pektsekye_PO()->getPluginPath() . 'Model/Option.php');		
        $optionModel =  new Pektsekye_ProductOptions_Model_Option();      
        $productOptions = $optionModel->getProductOptions($productId);
        if (count($productOptions) > 0){
          $hasOptions = true;
        }
      }
    
      if ( $hasOptions ){
        echo 'contains options';
      } else{
        echo 'does not contain options';
      }    
    

    To check if product has required options:

     
    $hasRequired = false;
    if (function_exists('Pektsekye_PO')){
      include_once(Pektsekye_PO()->getPluginPath() . 'Model/Option.php');		
      $optionModel =  new Pektsekye_ProductOptions_Model_Option();      
      $productOptions = $optionModel->getProductOptions($productId); 
      foreach ($productOptions as $option){      
        if ($option['required'] == 1){   
          $hasRequired = true;      
          break;           
        }              											                                                    
      }
    }
    
    if ($hasRequired){
      echo 'contains required options';
    } else{
      echo 'does not contain required options';
    }
    

    PS: don’t forget that such checking for each product can slow down the website.

    Stanislav

    Thread Starter samdo2

    (@samdo2)

    Thanks, but doesn’t work on the product catalog page.
    Error: Undefined variable $productId

    Plugin Author Pektsekye

    (@pektsekye)

    Hello,

    Can you send a link to the page where you need to use this code to my email [email protected]
    ?

    Stanislav

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Condition: if there is an option, then …?’ is closed to new replies.