Esempio n. 1
0
 public function delete($oid = null)
 {
     if ($attributes = $this->getAttributes($oid)) {
         DSCTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
         $table = DSCTable::getInstance('OrderItemAttributes', 'CitruscartTable');
         foreach ($attributes as $attribute) {
             if (!$table->delete($attribute->orderitemattribute_id)) {
                 $this->setError($table->getError());
             }
         }
     }
     $deleteItem = parent::delete($oid);
     return parent::check();
 }
Esempio n. 2
0
 /**
  * Adds an order history record to the DB for this order
  * @return unknown_type
  */
 protected function saveOrderHistory()
 {
     $order = $this->_order;
     $values = $this->_values;
     DSCTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $row = DSCTable::getInstance('OrderHistory', 'CitruscartTable');
     $row->order_id = $order->order_id;
     $row->order_state_id = $order->order_state_id;
     $row->notify_customer = '0';
     // don't notify the customer on prepayment
     $row->comments = isset($values['order_history_comments']) ? $values['order_history_comments'] : "";
     if (!$row->save()) {
         $this->setError($row->getError());
         return false;
     }
     return true;
 }
Esempio n. 3
0
 public function isAvailable()
 {
     // create cart object out of item properties
     $item = new JObject();
     $item->user_id = $this->user_id;
     $item->product_id = (int) $this->product_id;
     $item->product_qty = !empty($this->product_quantity) ? $this->product_quantity : '1';
     $item->product_attributes = $this->product_attributes;
     $item->vendor_id = $this->vendor_id;
     $item->cartitem_params = $this->wishlistitem_params;
     DSCTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
     $product = DSCTable::getInstance('Products', 'CitruscartTable');
     $product->load(array('product_id' => $this->product_id));
     if (empty($product->product_enabled) || empty($product->product_id)) {
         $this->setError(JText::_('COM_CITRUSCART_INVALID_PRODUCT'));
         return false;
     }
     if ($product->product_notforsale) {
         $this->setError(JText::_('COM_CITRUSCART_PRODUCT_NOT_FOR_SALE'));
         return false;
     }
     Citruscart::load('CitruscartHelperProduct', 'helpers.product');
     $product_helper = new CitruscartHelperProduct();
     $availableQuantity = $product_helper->getAvailableQuantity($item->product_id, $item->product_attributes);
     if ($availableQuantity->product_check_inventory && $item->product_qty > $availableQuantity->quantity) {
         $this->setError(JText::sprintf("COM_CITRUSCART_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $item->product_qty));
         return false;
     }
     $results = array();
     $dispatcher = JDispatcher::getInstance();
     $results = JFactory::getApplication()->triggerEvent("onIsWishlistItemAvailable", array(&$item));
     for ($i = 0; $i < count($results); $i++) {
         $result = $results[$i];
         if (!empty($result->error)) {
             $this->setError($result->message);
             return false;
         }
     }
     return true;
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 /**
  * One a new order,
  * increase the uses count on all the ordercoupons.
  *
  * @param $order_id
  * @return unknown_type
  */
 public function processOrder($order_id)
 {
     DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     $model = DSCModel::getInstance('Ordercoupons', 'CitruscartModel');
     $model->setState('filter_orderid', $order_id);
     if ($items = $model->getList()) {
         DSCTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables');
         $coupon = DSCTable::getInstance('Coupons', 'CitruscartTable');
         foreach ($items as $item) {
             $coupon->load(array('coupon_id' => $item->coupon_id));
             $coupon->coupon_uses = $coupon->coupon_uses + 1;
             if (!$coupon->save()) {
                 //JFactory::getApplication()->enqueueMessage( $coupon->getError() );
             }
         }
     }
 }