Esempio n. 1
0
 public static function getProducts()
 {
     JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models');
     $model = JModelLegacy::getInstance('Mycart', 'J2StoreModel');
     $db = JFactory::getDbo();
     //get the products from the cart
     $cartitems = $model->getDataNew();
     //now we have to prepare this data for adding into order table object
     $productitems = array();
     $cartitem = array();
     foreach ($cartitems as $cartitem) {
         if ($productItem = J2StoreHelperCart::getItemInfo($cartitem['product_id'])) {
             //base price
             $price = $productItem->price;
             //now get special price or discounted prices, if any
             $price_override = J2StorePrices::getPrice($productItem->product_id, $cartitem['quantity']);
             if (isset($price_override) && !empty($price_override)) {
                 $price = $price_override->product_price;
             }
             //$productItem->price = $productItem->product_price = $cartitem->product_price;
             // TODO Push this into the orders object->addItem() method?
             $orderItem = JTable::getInstance('OrderItems', 'Table');
             $orderItem->product_id = $productItem->product_id;
             $orderItem->orderitem_sku = $productItem->product_sku;
             $orderItem->orderitem_name = $productItem->product_name;
             $orderItem->orderitem_quantity = $cartitem['quantity'];
             //original price
             $orderItem->orderitem_price = $price;
             //save product options in the json format
             $product_options = J2StoreHelperCart::getReadableProductOptions($cartitem['option']);
             $orderItem->orderitem_attributes = $db->escape($product_options->product_option_json);
             $orderItem->orderitem_attribute_names = $db->escape($product_options->product_option_names);
             $orderItem->orderitem_attributes_price = $cartitem['option_price'];
             $orderItem->orderitem_final_price = ($orderItem->orderitem_price + $orderItem->orderitem_attributes_price) * $orderItem->orderitem_quantity;
             array_push($productitems, $orderItem);
         }
     }
     return $productitems;
 }
Esempio n. 2
0
 function getDataNew()
 {
     require_once JPATH_SITE . '/components/com_j2store/helpers/cart.php';
     $session = JFactory::getSession();
     // Lets load the content if it doesn't already exist
     if (empty($this->_data) && count($session->get('j2store_cart'))) {
         foreach ($session->get('j2store_cart') as $key => $quantity) {
             $product = explode(':', $key);
             $product_id = $product[0];
             $stock = true;
             // Options
             if (isset($product[1])) {
                 $options = unserialize(base64_decode($product[1]));
             } else {
                 $options = array();
             }
             //now get product details
             $product_info = J2StoreHelperCart::getItemInfo($product_id);
             //now get product options
             if ($product_info) {
                 $option_price = 0;
                 $option_weight = 0;
                 $option_data = array();
                 foreach ($options as $product_option_id => $option_value) {
                     $product_option = $this->getCartProductOptions($product_option_id, $product_id);
                     if ($product_option) {
                         if ($product_option->type == 'select' || $product_option->type == 'radio') {
                             //ok now get product option values
                             $product_option_value = $this->getCartProductOptionValues($product_option->product_option_id, $option_value);
                             if ($product_option_value) {
                                 //option price
                                 if ($product_option_value->product_optionvalue_prefix == '+') {
                                     $option_price += $product_option_value->product_optionvalue_price;
                                 } elseif ($product_option_value->product_optionvalue_prefix == '-') {
                                     $option_price -= $product_option_value->product_optionvalue_price;
                                 }
                                 //options weight
                                 if ($product_option_value->product_optionvalue_weight_prefix == '+') {
                                     $option_weight += $product_option_value->product_optionvalue_weight;
                                 } elseif ($product_option_value->product_optionvalue_weight_prefix == '-') {
                                     $option_weight -= $product_option_value->product_optionvalue_weight;
                                 }
                                 $option_data[] = array('product_option_id' => $product_option_id, 'product_optionvalue_id' => $option_value, 'option_id' => $product_option->option_id, 'optionvalue_id' => $product_option_value->optionvalue_id, 'name' => $product_option->option_name, 'option_value' => $product_option_value->optionvalue_name, 'type' => $product_option->type, 'price' => $product_option_value->product_optionvalue_price, 'price_prefix' => $product_option_value->product_optionvalue_prefix, 'weight' => $product_option_value->product_optionvalue_weight, 'option_sku' => $product_option_value->product_optionvalue_sku, 'weight_prefix' => $product_option_value->product_optionvalue_weight_prefix);
                             }
                         } elseif ($product_option->type == 'checkbox' && is_array($option_value)) {
                             foreach ($option_value as $product_optionvalue_id) {
                                 $product_option_value = $this->getCartProductOptionValues($product_option->product_option_id, $product_optionvalue_id);
                                 if ($product_option_value) {
                                     //option price
                                     if ($product_option_value->product_optionvalue_prefix == '+') {
                                         $option_price += $product_option_value->product_optionvalue_price;
                                     } elseif ($product_option_value->product_optionvalue_prefix == '-') {
                                         $option_price -= $product_option_value->product_optionvalue_price;
                                     }
                                     //option weight
                                     if ($product_option_value->product_optionvalue_weight_prefix == '+') {
                                         $option_weight += $product_option_value->product_optionvalue_weight;
                                     } elseif ($product_option_value->product_optionvalue_weight_prefix == '-') {
                                         $option_weight -= $product_option_value->product_optionvalue_weight;
                                     }
                                     $option_data[] = array('product_option_id' => $product_option_id, 'product_optionvalue_id' => $product_optionvalue_id, 'option_id' => $product_option->option_id, 'optionvalue_id' => $product_option_value->optionvalue_id, 'name' => $product_option->option_name, 'option_value' => $product_option_value->optionvalue_name, 'type' => $product_option->type, 'price' => $product_option_value->product_optionvalue_price, 'price_prefix' => $product_option_value->product_optionvalue_prefix, 'weight' => $product_option_value->product_optionvalue_weight, 'option_sku' => $product_option_value->product_optionvalue_sku, 'weight_prefix' => $product_option_value->product_optionvalue_weight_prefix);
                                 }
                             }
                         } elseif ($product_option->type == 'text' || $product_option->type == 'textarea' || $product_option->type == 'date' || $product_option->type == 'datetime' || $product_option->type == 'time') {
                             $option_data[] = array('product_option_id' => $product_option_id, 'product_optionvalue_id' => '', 'option_id' => $product_option->option_id, 'optionvalue_id' => '', 'name' => $product_option->option_name, 'option_value' => $option_value, 'type' => $product_option->type, 'price' => '', 'price_prefix' => '', 'weight' => '', 'weight_prefix' => '');
                         }
                     }
                 }
                 //get the product price
                 //base price
                 $price = $product_info->price;
                 //we may have special price or discounts. so check
                 $price_override = J2StorePrices::getPrice($product_info->product_id, $quantity);
                 if (isset($price_override) && !empty($price_override)) {
                     $price = $price_override->product_price;
                 }
                 $this->_data[$key] = array('key' => $key, 'product_id' => $product_info->product_id, 'name' => $product_info->product_name, 'model' => $product_info->product_sku, 'raw_options' => $options, 'option' => $option_data, 'option_price' => $option_price, 'quantity' => $quantity, 'stock' => $product_info, 'tax_profile_id' => $product_info->tax_profile_id, 'shipping' => $product_info->item_shipping, 'price' => $price + $option_price, 'total' => ($price + $option_price) * $quantity, 'weight' => $product_info->item_weight + $option_weight, 'weight_total' => ($product_info->item_weight + $option_weight) * $quantity, 'option_weight' => $option_weight * $quantity, 'weight_class_id' => $product_info->item_weight_class_id, 'length' => $product_info->item_length, 'width' => $product_info->item_width, 'height' => $product_info->item_height, 'length_class_id' => $product_info->item_length_class_id);
             } else {
                 $this->remove($key);
             }
         }
     }
     return $this->_data;
 }
Esempio n. 3
0
 /**
  * Method to getItem
  * @params type int id
  * @result products
  */
 public function getItem()
 {
     $id = $this->getId();
     $product = J2StoreHelperCart::getItemInfo($id);
     //set the correct quantity
     if (isset($product->min_sale_qty) && $product->min_sale_qty > 1 && J2STORE_PRO == 1) {
         $product->product_quantity = (int) $product->min_sale_qty;
         $product->item_minimum_notice = JText::sprintf('J2STORE_MINIMUM_QUANTITY_NOTIFICATION', $product->product_name, (int) $product->min_sale_qty);
     } else {
         $product->product_quantity = 1;
     }
     //include the model file path
     JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_j2store/models');
     //create obj for cartmodel class
     $cart_model = JModelLegacy::getInstance('Mycart', 'J2StoreModel');
     //now get the productoptions based on the id
     $attributes = $cart_model->getProductOptions($id);
     //let calcuate the product option based on the stock
     if (count($attributes) && $product->manage_stock == 1 && J2STORE_PRO == 1) {
         //get unavailable attribute options
         $attributes = $cart_model->processAttributeOptions($attributes, $product);
     }
     //assign the attributes
     $product->attributes = $attributes;
     //assign th prices
     $product->prices = J2StorePrices::getPrice($id, $product->product_quantity);
     if (J2STORE_PRO == 1 && $product->manage_stock == 1) {
         JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/models');
         $qtyModel = JModelLegacy::getInstance('ProductQuantities', 'J2StoreModel');
         $qtyModel->setState('filter_product', $product->product_id);
         $qtyModel->setState('filter_productid', $product->product_id);
         $product->option_stock = $qtyModel->getList();
         $product->product_stock = $qtyModel->getQuantityTotal();
     } else {
         $product->product_stock = 99;
     }
     $product->product = $product;
     $product->inventory = J2StoreInventory::isAllowed($product);
     //get all tags
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $product->product_tags = $this->getProductTags($id);
     }
     $this->executePlugins($product);
     return $product;
 }