$changed_attr = isset($values['changed_attr']) ? $values['changed_attr'] : -1;
$changed_pao = -1;
if ($changed_attr > -1) {
    $changed_pao = $values['attribute_' . $changed_attr];
}
Citruscart::load('CitruscartHelperBase', 'helpers._base');
$js_strings = array('COM_CITRUSCART_UPDATING_ATTRIBUTES');
CitruscartHelperBase::addJsTranslationStrings($js_strings);
$helper_product = CitruscartHelperBase::getInstance('Product');
// Selected attribute options (for child attributes)
$selected_opts = !empty($this->selected_opts) ? json_decode($this->selected_opts) : 0;
if (!count($selected_opts)) {
    $selected_opts = 0;
}
$attributes = CitruscartHelperProduct::getAttributes($row->product_id, $selected_opts);
$default = CitruscartHelperProduct::getDefaultAttributeOptions($attributes);
// First view of the page: select the first value in the list
if (!$selected_opts) {
    $selected_opts = $default;
    $selected_opts[] = 0;
}
foreach ($attributes as $attribute) {
    ?>
        <div class="pao" id='productattributeoption_<?php 
    echo $attribute->productattribute_id;
    ?>
'>
            <?php 
    echo "<span>" . $attribute->productattribute_name . " : </span>";
    $key = 'attribute_' . $attribute->productattribute_id;
    $selected = !empty($values[$key]) ? $values[$key] : $default[$attribute->productattribute_id];
Example #2
0
 public static function calculateProductAttributeProperty(&$product, $attributes, $product_price, $product_weight)
 {
     Citruscart::load('CitruscartHelperBase', 'helpers._base');
     $helper_product = CitruscartHelperBase::getInstance('Product');
     // first we get rid off phantom attributes (the ones that should be hidden because their parent attribute was just unselected)
     $attr_base = CitruscartHelperProduct::getAttributes($product->product_id, array_merge($attributes, array('0')));
     $attr_final = CitruscartHelperProduct::getDefaultAttributeOptions($attr_base);
     foreach ($attr_final as $key => $value) {
         if (isset($attributes['attribute_' . $key])) {
             $attr_final[$key] = $attributes['attribute_' . $key];
         }
     }
     Citruscart::load('CitruscartQuery', 'library.query');
     $q = new CitruscartQuery();
     $q->select('tbl.`productattributeoption_price` , tbl.`productattributeoption_prefix`, tbl.`productattributeoption_id` ');
     $q->select('tbl.`productattributeoption_code`, tbl.`productattributeoption_weight`, tbl.`productattributeoption_prefix_weight`');
     $q->from('`#__citruscart_productattributeoptions` tbl');
     $q->join('left', '`#__citruscart_productattributes` atr ON tbl.	productattribute_id = atr.productattribute_id');
     $q->where("tbl.productattributeoption_id IN ('" . implode("', '", $attr_final) . "')");
     $q->order('atr.ordering ASC');
     $db = JFactory::getDbo();
     $db->setQuery($q);
     $res = $db->loadObjectList();
     $attributes = array();
     for ($i = 0, $c = count($res); $i < $c; $i++) {
         // update product price
         // is not + or -
         if ($res[$i]->productattributeoption_prefix == '=') {
             $product->{$product_price} = floatval($res[$i]->productattributeoption_price);
         } else {
             $product->{$product_price} = $product->{$product_price} + floatval($res[$i]->productattributeoption_prefix . $res[$i]->productattributeoption_price);
         }
         // update product weight
         if ($res[$i]->productattributeoption_prefix_weight == '=') {
             $product->{$product_weight} = floatval($res[$i]->productattributeoption_weight);
         } else {
             $product->{$product_weight} = $product->{$product_weight} + floatval($res[$i]->productattributeoption_prefix_weight . $res[$i]->productattributeoption_weight);
         }
         $attributes[] = $res[$i]->productattributeoption_id;
     }
     $product->sku = self::getProductSKU($product, $attributes);
 }