Beispiel #1
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_citruscart&view=orderitems&task=edit&id=' . $item->orderitem_id;
     }
     return $list;
 }
Beispiel #2
0
 public function getList($refresh = false, $getEav = true, $options = array())
 {
     static $pa, $pao;
     if (empty($pa)) {
         $pa = array();
     }
     if (empty($pao)) {
         $pao = array();
     }
     Citruscart::load("CitruscartHelperUser", 'helpers.user');
     Citruscart::load('CitruscartHelperSubscription', 'helpers.subscription');
     $user_helper = CitruscartHelperBase::getInstance('User');
     $product_helper = CitruscartHelperBase::getInstance('Product');
     if (empty($this->_list)) {
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
         $items = parent::getList($refresh);
         // If no item in the list, return an array()
         if (empty($items)) {
             return array();
         }
         foreach ($items as $item) {
             $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()->toSql());
             //checking if we do price override
             isset($item->product_price_override->override) ? $item->product_price_override = true : "";
             if (!empty($item->product_price_override)) {
                 $item->product_price = isset($item->product_price_override->product_price) ? $item->product_price_override->product_price : "";
             }
             if ($item->product_recurs) {
                 $item->recurring_price = $item->product_price;
                 if ($item->subscription_prorated) {
                     $result = CitruscartHelperSubscription::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';
             $item->orderitem_attributes_weight = '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] = JTable::getInstance('ProductAttributeOptions', 'CitruscartTable');
                         $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;
                         $item->product_price_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;
                     }
                     // update the weight
                     // + or -
                     if ($table->productattributeoption_prefix_weight != '=') {
                         $item->product_weight = $item->product_weight + floatval("{$table->productattributeoption_prefix_weight}" . "{$table->productattributeoption_weight}");
                         // store the attribute's price impact
                         $item->orderitem_attributes_weight = $item->orderitem_attributes_weight + floatval("{$table->productattributeoption_prefix_weight}" . "{$table->productattributeoption_weight}");
                     } else {
                         // assign the product attribute price as the product price
                         //then set the orderitem_attributes_price to 0.0000
                         $item->product_weight = $table->productattributeoption_weight;
                         //
                         // store the attribute's price impact
                         $item->orderitem_attributes_weight = "0.00000";
                     }
                     // update product values based on the selected option
                     $m_values = DSCModel::getInstance('ProductAttributeOptionValues', 'CitruscartModel');
                     $m_values->setState('filter_option', $attrib_id);
                     $list_values = $m_values->getList();
                     if (count($list_values)) {
                         foreach ($list_values as $val) {
                             switch ($val->productattributeoptionvalue_field) {
                                 case 'product_model':
                                 case 'product_sku':
                                     $field = $val->productattributeoptionvalue_field;
                                     switch ($val->productattributeoptionvalue_operator) {
                                         case 'prepend':
                                             $item->{$field} = $val->productattributeoptionvalue_value . $item->{$field};
                                             break;
                                         case 'append':
                                             $item->{$field} = $item->{$field} . $val->productattributeoptionvalue_value;
                                             break;
                                         case 'replace':
                                             $item->{$field} = $val->productattributeoptionvalue_value;
                                             break;
                                     }
                                     break;
                             }
                         }
                     }
                     $item->orderitem_attributes_price = number_format($item->orderitem_attributes_price, '5', '.', '');
                     $item->orderitem_attributes_weight = number_format($item->orderitem_attributes_weight, '5', '.', '');
                     // store a csv of the attrib names, built by Attribute name + Attribute option name
                     if (empty($pa[$table->productattribute_id])) {
                         $pa[$table->productattribute_id] = JTable::getInstance('ProductAttributes', 'CitruscartTable');
                         $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);
                     }
                 }
                 // Generate Product Sku based upon attributes
                 $item->product_sku = CitruscartHelperProduct::getProductSKU($item, $attibutes_array);
                 // 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->prepareItem($item, 0, $refresh);
         }
         $this->_list = $items;
     }
     return $this->_list;
 }
Beispiel #3
0
 /**
  * Clean the cache
  *
  * @return  void
  *
  * @since   11.1
  */
 public function clearCache()
 {
     parent::clearCache();
     self::clearCacheAuxiliary();
 }