Beispiel #1
0
 /**
  * Set basic properties for the item, whether in a list or a singleton
  *
  * @param unknown_type $item
  * @param unknown_type $key
  * @param unknown_type $refresh
  */
 protected function prepareItem(&$item, $key = 0, $refresh = false)
 {
     Tienda::load("TiendaHelperProduct", 'helpers.product');
     Tienda::load('TiendaHelperSubscription', 'helpers.subscription');
     $helper_product = new TiendaHelperProduct();
     if (!empty($item->product_recurs)) {
         $item->recurring_price = $item->price;
         if ($item->subscription_prorated) {
             Tienda::load('TiendaHelperSubscription', 'helpers.subscription');
             $result = TiendaHelperSubscription::calculateProRatedTrial($item->subscription_prorated_date, $item->subscription_prorated_term, $item->recurring_period_unit, $item->recurring_trial_price, $item->subscription_prorated_charge);
             $item->price = $result['price'];
             $item->prorated_price = $result['price'];
             $item->prorated_interval = $result['interval'];
             $item->prorated_unit = $result['unit'];
             // $item->recurring_trial = $result['trial'];
         } else {
             if (!empty($item->recurring_trial)) {
                 $item->price = $item->recurring_trial_price;
             }
         }
     }
     $user_id = $this->getState('user.id', 0);
     $qty = $this->getState('product.qty', -1);
     if ($qty > -1) {
         $user_group = TiendaHelperUser::getUserGroup($user_id, $item->product_id);
         $price = TiendaHelperProduct::getPrice($item->product_id, $qty, $user_group);
         $item->price = $price->product_price;
     }
     $item->product_parameters = new DSCParameter($item->product_params);
     $item->slug = $item->product_alias ? ":{$item->product_alias}" : "";
     $item->link = 'index.php?option=com_tienda&view=products&task=view&id=' . $item->product_id;
     $item->link_edit = 'index.php?option=com_tienda&view=products&task=edit&id=' . $item->product_id;
     $item->product_categories = $this->getCategories($item->product_id);
     $item->default_attributes = $helper_product->getDefaultAttributes($item->product_id);
     $item->product_classes = null;
     foreach ($item->product_categories as $cat) {
         $item->product_classes .= " " . $cat->category_alias;
     }
     if (!empty($item->product_class_suffix)) {
         $item->product_classes .= " " . $item->product_class_suffix;
     }
     $item->product_classes = trim($item->product_classes);
     parent::prepareItem($item, $key, $refresh);
 }
Beispiel #2
0
 /**
  * Adds an item to the order object
  * $item can be a named array with a minimum of 'product_id' and 'orderitem_quantity' and 'orderitem_attributes' (as CSV of productattributeoptions_ids)
  * $item can be an object with minimum of 'product_id' and 'orderitem_quantity' and 'orderitem_attributes' properties
  * $item can be a 'product_id' string
  * 
  * $this->_items['product_id'] = TableOrderItems() object;
  * 
  * @param object    $item   TableOrderItem object
  * @return void
  */
 function addItem($item)
 {
     Tienda::load('TiendaHelperSubscription', 'helpers.subscription');
     $orderItem = JTable::getInstance('OrderItems', 'TiendaTable');
     if (is_array($item)) {
         $orderItem->bind($item);
     } elseif (is_object($item) && is_a($item, 'TiendaTableOrderItems')) {
         $orderItem = $item;
     } elseif (is_object($item)) {
         $orderItem->product_id = @$item->product_id;
         $orderItem->orderitem_quantity = @$item->orderitem_quantity;
         $orderItem->vendor_id = @$item->vendor_id;
         $orderItem->orderitem_attributes = @$item->orderitem_attributes;
     } else {
         $orderItem->product_id = $item;
         $orderItem->orderitem_quantity = '1';
         $orderItem->vendor_id = '0';
         $orderItem->orderitem_attributes = '';
     }
     // check whether/not the item recurs
     JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
     $model = JModel::getInstance('Products', 'TiendaModel');
     $model->setId($orderItem->product_id);
     $product = $model->getItem();
     $orderItem->subscription_prorated = $product->subscription_prorated;
     // flag the order as recurring
     if ($product->product_recurs) {
         $this->order_recurs = true;
     }
     if ($orderItem->subscription_prorated) {
         // set the orderitem's recurring product values
         $orderItem->orderitem_recurs = $product->product_recurs;
         $orderItem->recurring_price = $product->recurring_price;
         $orderItem->recurring_payments = $product->recurring_payments;
         $orderItem->recurring_period_interval = $product->recurring_period_interval;
         $orderItem->recurring_period_unit = $product->recurring_period_unit;
         $orderItem->recurring_trial_price = $product->recurring_trial_price;
         if ($product->subscription_prorated) {
             $result = TiendaHelperSubscription::calculateProRatedTrial($product->subscription_prorated_date, $product->subscription_prorated_term, $product->recurring_period_unit, $product->recurring_trial_price, $product->subscription_prorated_charge);
             $orderItem->recurring_trial = $result['trial'];
             $orderItem->recurring_trial_period_interval = $result['interval'];
             $orderItem->recurring_trial_period_unit = $result['unit'];
             $orderItem->recurring_trial_price = $result['price'];
         } else {
             $orderItem->recurring_trial = $product->recurring_trial;
             $orderItem->recurring_trial_period_interval = $product->recurring_trial_period_interval;
             $orderItem->recurring_trial_period_unit = $product->recurring_trial_period_unit;
         }
     }
     if (!empty($product->product_subscription)) {
         // set the orderitem's subscription product values
         $orderItem->orderitem_subscription = $product->product_subscription;
         $orderItem->subscription_lifetime = $product->subscription_lifetime;
         $orderItem->subscription_period_interval = $product->subscription_period_interval;
         $orderItem->subscription_period_unit = $product->subscription_period_unit;
     }
     // Use hash to separate items when customer is buying the same product from multiple vendors
     // and with different attribs
     $hash = intval($orderItem->product_id) . "." . intval($orderItem->vendor_id) . "." . $orderItem->orderitem_attributes;
     $dispatcher = JDispatcher::getInstance();
     $results = $dispatcher->trigger("onGetAdditionalOrderitemKeyValues", array($orderItem));
     //              JFactory::getApplication()->enqueueMessage( 'orders.php - line 236 - '.Tienda::dump( $results ) );
     foreach ($results as $result) {
         foreach ($result as $key => $value) {
             $hash = $hash . "." . $value;
         }
     }
     if (isset($orderItem->cart_id)) {
         unset($orderItem->cart_id);
     }
     //              $orderItem->orderitem_id = null; // so it can create a new ordreitem, if needed
     if (!empty($this->_items[$hash])) {
         // merely update quantity if item already in list
         $this->_items[$hash]->orderitem_quantity += $orderItem->orderitem_quantity;
     } else {
         $this->_items[$hash] = $orderItem;
     }
     // add the vendor to the order
     $this->addVendor($orderItem);
     // add productdownloads records to the order
     // not necessary yet
     // $this->addDownloads( $orderItem );
 }
Beispiel #3
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;
 }