コード例 #1
0
ファイル: cart.php プロジェクト: ForAEdesWeb/AEW4
 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;
 }