Ejemplo n.º 1
0
if (!empty($this->display_cartbutton)) {
    ?>
    
    <!--attribute options-->
    <div id='product_attributeoptions_<?php 
    echo $item->product_id;
    ?>
' class="product_attributeoptions">
    <?php 
    // 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 = TiendaHelperProduct::getAttributes($item->product_id, $selected_opts);
    $default = TiendaHelperProduct::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];
Ejemplo n.º 2
0
 public static function calculateProductAttributeProperty(&$product, $attributes, $product_price, $product_weight)
 {
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper_product = TiendaHelperBase::getInstance('Product');
     // first we get rid off phantom attributes (the ones that should be hidden because their parent attribute was just unselected)
     $attr_base = TiendaHelperProduct::getAttributes($product->product_id, array_merge($attributes, array('0')));
     $attr_final = TiendaHelperProduct::getDefaultAttributeOptions($attr_base);
     foreach ($attr_final as $key => $value) {
         if (isset($attributes['attribute_' . $key])) {
             $attr_final[$key] = $attributes['attribute_' . $key];
         }
     }
     Tienda::load('TiendaQuery', 'library.query');
     $q = new TiendaQuery();
     $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('`#__tienda_productattributeoptions` tbl');
     $q->join('left', '`#__tienda_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);
 }