示例#1
0
 /**
  * Will return all the CSV combinations possible from a product's attribute options
  *
  * @param unknown_type $product_id
  * @param $attributeOptionId
  * @return unknown_type
  */
 static function getProductAttributeCSVs($product_id, $attributeOptionId = '0')
 {
     $return = array();
     $traits = array();
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     // get all productattributes
     $model = JModelLegacy::getInstance('ProductAttributes', 'CitruscartModel');
     $model->setState('filter_product', $product_id);
     if ($attributes = $model->getList()) {
         foreach ($attributes as $attribute) {
             $paoModel = JModelLegacy::getInstance('ProductAttributeOptions', 'CitruscartModel');
             $paoModel->setState('filter_attribute', $attribute->productattribute_id);
             if ($paos = $paoModel->getList()) {
                 $options = array();
                 foreach ($paos as $pao) {
                     // Genrate the arrray of single value with the id of newly created attribute option
                     if ($attributeOptionId == $pao->productattributeoption_id) {
                         $newOption = array();
                         $newOption[] = (string) $attributeOptionId;
                         $options = $newOption;
                         break;
                     }
                     $options[] = $pao->productattributeoption_id;
                 }
                 $traits[] = $options;
             }
         }
     }
     // run recursive function on the data
     CitruscartHelperProduct::getCombinations("", $traits, 0, $return);
     // before returning them, loop through each record and sort them
     $result = array();
     foreach ($return as $csv) {
         $values = explode(',', $csv);
         sort($values);
         $result[] = implode(',', $values);
     }
     return $result;
 }