Ejemplo n.º 1
0
 public function getList($refresh = false, $getEav = true, $options = array())
 {
     static $pa, $pao;
     if (empty($pa)) {
         $pa = array();
     }
     if (empty($pao)) {
         $pao = array();
     }
     Tienda::load("TiendaHelperUser", 'helpers.user');
     Tienda::load('TiendaHelperSubscription', 'helpers.subscription');
     $user_helper = TiendaHelperBase::getInstance('User');
     $product_helper = TiendaHelperBase::getInstance('Product');
     if (empty($this->_list) || $refresh) {
         DSCTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
         $items = parent::getList($refresh);
         // If no item in the list, return an array()
         if (empty($items)) {
             return array();
         }
         foreach ($items as $item) {
             if (empty($item->product_qty)) {
                 $item->product_qty = '1';
             }
             $filter_group = $user_helper->getUserGroup(JFactory::getUser()->id, $item->product_id);
             // at this point, ->product_price holds the default price for the product,
             // but the user may qualify for a discount based on volume or date, so let's get that price override
             $item->product_price_override = $product_helper->getPrice($item->product_id, $item->product_qty, $filter_group, JFactory::getDate()->toMySQL());
             //checking if we do price override
             $item->product_price_override->override = true;
             if (!empty($item->product_price_override)) {
                 $item->product_price = $item->product_price_override->product_price;
             }
             if ($item->product_recurs) {
                 $item->recurring_price = $item->product_price;
                 if ($item->subscription_prorated) {
                     $result = TiendaHelperSubscription::calculateProRatedTrial($item->subscription_prorated_date, $item->subscription_prorated_term, $item->recurring_period_unit, $item->recurring_trial_price, $item->subscription_prorated_charge);
                     $item->product_price = $result['price'];
                     $item->recurring_trial_price = $result['price'];
                     $item->recurring_trial_period_interval = $result['interval'];
                     $item->recurring_trial_period_unit = $result['unit'];
                     $item->recurring_trial = $result['trial'];
                 } else {
                     if ($item->recurring_trial) {
                         $item->product_price = $item->recurring_trial_price;
                     }
                 }
             }
             $item->product_parameters = new DSCParameter($item->product_params);
             $item->orderitem_attributes_price = '0.00000';
             $attributes_names = array();
             if (!empty($item->product_attributes)) {
                 $item->attributes = array();
                 // array of each selected attribute's object
                 $attibutes_array = explode(',', $item->product_attributes);
                 foreach ($attibutes_array as $attrib_id) {
                     if (empty($pao[$attrib_id])) {
                         // load the attrib's object
                         $pao[$attrib_id] = DSCTable::getInstance('ProductAttributeOptions', 'TiendaTable');
                         $pao[$attrib_id]->load($attrib_id);
                     }
                     $table = $pao[$attrib_id];
                     // update the price
                     // + or -
                     if ($table->productattributeoption_prefix != '=') {
                         $item->product_price = $item->product_price + floatval("{$table->productattributeoption_prefix}" . "{$table->productattributeoption_price}");
                         // store the attribute's price impact
                         $item->orderitem_attributes_price = $item->orderitem_attributes_price + floatval("{$table->productattributeoption_prefix}" . "{$table->productattributeoption_price}");
                         $item->product_price_override->override = true;
                     } else {
                         // assign the product attribute price as the product price
                         //then set the orderitem_attributes_price to 0.0000
                         $item->product_price = $table->productattributeoption_price;
                         //
                         // store the attribute's price impact
                         $item->orderitem_attributes_price = "0.00000";
                         $item->product_price_override->override = false;
                     }
                     $item->orderitem_attributes_price = number_format($item->orderitem_attributes_price, '5', '.', '');
                     $item->product_sku .= $table->productattributeoption_code;
                     // store a csv of the attrib names, built by Attribute name + Attribute option name
                     if (empty($pa[$table->productattribute_id])) {
                         $pa[$table->productattribute_id] = DSCTable::getInstance('ProductAttributes', 'TiendaTable');
                         $pa[$table->productattribute_id]->load($table->productattribute_id);
                     }
                     $atable = $pa[$table->productattribute_id];
                     if (!empty($atable->productattribute_id)) {
                         $name = JText::_($atable->productattribute_name) . ': ' . JText::_($table->productattributeoption_name);
                         $attributes_names[] = $name;
                     } else {
                         $attributes_names[] = JText::_($table->productattributeoption_name);
                     }
                 }
                 // Could someone explain to me why this is necessary?
                 if ($item->orderitem_attributes_price >= 0) {
                     // formatted for storage in the DB
                     $item->orderitem_attributes_price = "+{$item->orderitem_attributes_price}";
                 }
             }
             $item->attributes_names = implode(', ', $attributes_names);
         }
         $this->_list = $items;
     }
     return $this->_list;
 }
Ejemplo n.º 2
0
 /**
  * Clean the cache
  *
  * @return  void
  *
  * @since   11.1
  */
 public function clearCache()
 {
     parent::clearCache();
     self::clearCacheAuxiliary();
 }
Ejemplo n.º 3
0
 public function getList($refresh = false, $getEav = true, $options = array())
 {
     $list = parent::getList($refresh, $getEav, $options);
     // If no item in the list, return an array()
     if (empty($list)) {
         return array();
     }
     foreach ($list as $item) {
         $item->link = 'index.php?option=com_tienda&view=orderitems&task=edit&id=' . $item->orderitem_id;
     }
     return $list;
 }