function getProductsInfo() { Tienda::load("TiendaHelperProduct", 'helpers.product'); $product_helper = TiendaHelperBase::getInstance('Product'); DSCModel::addIncludePath(JPATH_SITE . DS . 'components/com_tienda/models'); DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $model = DSCModel::getInstance('Carts', 'TiendaModel'); $session = JFactory::getSession(); $user_id = $session->get('user_id', '', 'tienda_pos'); $model->setState('filter_user', $user_id); Tienda::load("TiendaHelperBase", 'helpers._base'); Tienda::load("TiendaHelperCarts", 'helpers.carts'); $user_helper = TiendaHelperBase::getInstance('User'); $filter_group = $user_helper->getUserGroup($user_id); $model->setState('filter_group', $filter_group); $cartitems = $model->getList(); $productitems = array(); foreach ($cartitems as $cartitem) { //echo Tienda::dump($cartitem); unset($productModel); $productModel = DSCModel::getInstance('Products', 'TiendaModel'); $filter_group = $user_helper->getUserGroup($user_id, $cartitem->product_id); $productModel->setState('filter_group', $filter_group); $productModel->setId($cartitem->product_id); if ($productItem = $productModel->getItem(false)) { $productItem->price = $productItem->product_price = !$cartitem->product_price_override->override ? $cartitem->product_price : $productItem->price; //we are not overriding the price if its a recurring && price if (!$productItem->product_recurs && $cartitem->product_price_override->override) { // 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 // TODO Shouldn't we remove this? Is it necessary? $cartitem has already done this in the carts model! $productItem->product_price_override = $product_helper->getPrice($productItem->product_id, $cartitem->product_qty, $filter_group, JFactory::getDate()->toMySQL()); if (!empty($productItem->product_price_override)) { $productItem->product_price = $productItem->product_price_override->product_price; } } if ($productItem->product_check_inventory) { // using a helper file,To determine the product's information related to inventory $availableQuantity = $product_helper->getAvailableQuantity($productItem->product_id, $cartitem->product_attributes); if ($availableQuantity->product_check_inventory && $cartitem->product_qty > $availableQuantity->quantity && $availableQuantity->quantity >= 1) { JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_TIENDA_CART_QUANTITY_ADJUSTED', $productItem->product_name, $cartitem->product_qty, $availableQuantity->quantity)); $cartitem->product_qty = $availableQuantity->quantity; } // removing the product from the cart if it's not available if ($availableQuantity->quantity == 0) { if (empty($cartitem->user_id)) { TiendaHelperCarts::removeCartItem($session_id, $cartitem->user_id, $cartitem->product_id); } else { TiendaHelperCarts::removeCartItem($cartitem->session_id, $cartitem->user_id, $cartitem->product_id); } JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_TIENDA_NOT_AVAILABLE') . " " . $productItem->product_name); continue; } } // TODO Push this into the orders object->addItem() method? $orderItem = JTable::getInstance('OrderItems', 'TiendaTable'); $orderItem->product_id = $productItem->product_id; $orderItem->orderitem_sku = $cartitem->product_sku; $orderItem->orderitem_name = $productItem->product_name; $orderItem->orderitem_quantity = $cartitem->product_qty; $orderItem->orderitem_price = $productItem->product_price; $orderItem->orderitem_attributes = $cartitem->product_attributes; $orderItem->orderitem_attribute_names = $cartitem->attributes_names; $orderItem->orderitem_attributes_price = $cartitem->orderitem_attributes_price; $orderItem->orderitem_final_price = ($orderItem->orderitem_price + $orderItem->orderitem_attributes_price) * $orderItem->orderitem_quantity; $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger("onGetAdditionalOrderitemKeyValues", array($cartitem)); foreach ($results as $result) { foreach ($result as $key => $value) { $orderItem->set($key, $value); } } // TODO When do attributes for selected item get set during admin-side order creation? array_push($productitems, $orderItem); } } return $productitems; }
/** * Checks the integrity of a cart * to make sure all dependencies are met * * @param $cart_id * @param $id_type * @return unknown_type */ function checkIntegrity($cart_id, $id_type = 'user_id') { $user_id = 0; $session_id = ''; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); // get the cart's items as well as user info (if logged in) $model = JModel::getInstance('Carts', 'TiendaModel'); switch ($id_type) { case "session": case "session_id": $model->setState('filter_session', $cart_id); $session_id = $cart_id; break; case "user": case "user_id": default: $model->setState('filter_user', $cart_id); $user_id = $cart_id; break; } $carthelper = new TiendaHelperCarts(); // get the cart items $cart_items = $model->getList(false, false); if (!empty($cart_items)) { // foreach foreach ($cart_items as $citem) { if (!$carthelper->canAddItem($citem, $cart_id, $id_type)) { JFactory::getApplication()->enqueueMessage(JText::_('COM_TIENDA_REMOVING_ITEM_FROM_CART_FOR_FAILED_DEPENDENCIES') . " - " . $citem->product_name, 'message'); $carthelper->removeCartItem($session_id, $user_id, $citem->product_id); } } } return true; }