public static function getProducts() { JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_k2store/models'); $model = JModelLegacy::getInstance('Mycart', 'K2StoreModel'); $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 = K2StoreHelperCart::getItemInfo($cartitem['product_id'])) { //base price $price = $productItem->price; //now get special price or discounted prices, if any $price_override = K2StorePrices::getPrice($productItem->product_id, $cartitem['quantity']); if (isset($price_override) && !empty($price_override)) { $price = 0; } //$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 = K2StoreHelperCart::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']; /*poparada hack*/ if ($orderItem->orderitem_attributes_price > 0) { $final_price = $orderItem->orderitem_attributes_price; } else { $final_price = $orderItem->orderitem_price + $orderItem->orderitem_attributes_price; } $orderItem->orderitem_final_price = $final_price * $orderItem->orderitem_quantity; array_push($productitems, $orderItem); } } // var_dump($productitems); return $productitems; }