/** * This method check whether user bought the product or not. * * @param integer $c_id cart id. * @param array $cartitem items detail 0=> array of basic info,1=>selection option info. 2=> attribute info. * @param integer $cart_item_id cart item id while updating the cart from checkout view. * * @since 2.2.2 * * @return boolean true or false. */ public function putCartitem($c_id, $cartitem, $cart_item_id = '') { $comquick2cartHelper = new comquick2cartHelper(); $params = JComponentHelper::getParams('com_quick2cart'); $item_details = $cartitem[0]; // Option details size->big,medium $item_options = isset($cartitem[1]) ? $cartitem[1] : null; // Attribute details $item_attris = isset($cartitem[2]) ? $cartitem[2] : null; if (!$c_id) { $c_id = $this->getCartId(); } // Get current item store id. $currItemStoreId = $comquick2cartHelper->getSoreID($item_details['item_id']); $singleStoreCkout = $params->get('singleStoreCkout', 0); if ($singleStoreCkout) { $status = $this->isProdFromSameStore($c_id, $currItemStoreId); // If not from same store. if (!$status) { return 2; } } $timestamp = date("Y-m-d H:i:s"); $opt_price = 0; $opt = $opt_ids = ''; $matchAttr = 1; // Product has attributes. if ($item_attris) { foreach ($item_attris as $item_attri) { $item_option = $item_options[$item_attri['itemattribute_id']]; $opt .= $item_attri['itemattribute_name'] . ": " . $item_option['itemattributeoption_name'] . ","; $opt_ids .= $item_option['itemattributeoption_id'] . ","; if ($item_option['itemattributeoption_prefix'] == '+') { $opt_price += $item_option['optionprice']; } elseif ($item_option['itemattributeoption_prefix'] == '-') { $opt_price -= $item_option['optionprice']; } } // Trim last comma, //$opt_ids = rtrim($opt_ids, ','); } $query = "Select cart_item_id,item_id,product_quantity\n\t\t FROM #__kart_cartitems WHERE cart_id=" . (int) $c_id . " AND item_id=" . $item_details['item_id'] . " AND product_attributes='" . $opt_ids . "' AND `product_attribute_names` = '" . $opt . "'"; $this->_db->setQuery($query); $cart = $this->_db->loadAssoc(); //~ $cart = $this->_db->loadAssocList(); //~ print"<pre>"; print_r($cartitem); //~ print"<pre>"; print_r($cart); die; $final_price = $item_details['price'] + $opt_price; $items = new stdClass(); $items->product_final_price = $item_details['count'] * $final_price; $items->product_item_price = $item_details['price']; $items->product_attributes = $opt_ids; $items->product_attribute_names = $opt; $items->product_attributes_price = $opt_price; $items->mdate = $timestamp; $items->currency = $comquick2cartHelper->getCurrencySession(); $items->store_id = $comquick2cartHelper->getSoreID($item_details['item_id']); // getting store id from item_id //~ if (!empty($params)) //~ { //~ $items->params = $params; //~ } /* if #__kart_cartitems contain entry then update .if cart contain item then update// check present same && all attr same */ if ($cart['cart_item_id'] && $cart['item_id'] == $item_details['item_id']) { //~ print"<pre>"; print $cart_item_id; //~ print"<pre>"; print_r($cart); //~ print"<pre>"; print_r($item_details); //~ die; // Just clicking on refresh button if ($cart_item_id && $cart['cart_item_id'] == $cart_item_id) { $final_qty = $item_details['count']; } else { $final_qty = $cart['product_quantity'] + $item_details['count']; } $minmax = $comquick2cartHelper->getMinMax($item_details['item_id']); // not equal to nulll,0 etc if (!empty($minmax['min_quantity']) && !empty($minmax['max_quantity'])) { if ($final_qty < $minmax['min_quantity'] || $final_qty > $minmax['max_quantity'] || $cart['product_quantity'] < 1) { return JText::sprintf('COM_QUICK2CART_MIN_MAX_ERROR_SUD_BE_INRANGE', $minmax['min_quantity'], $minmax['max_quantity']); ""; } } $slabquantity = $item_details['count'] % $minmax['slab']; if ($slabquantity != 0) { return JText::sprintf('COM_QUICK2CART_QUANTITY_SHOULD_BE_MULI_OF_SLAB', $minmax['slab']); } $items->product_quantity = $final_qty; $items->cart_item_id = $cart['cart_item_id']; $items->product_final_price = $items->product_quantity * $final_price; if (!$this->_db->updateObject('#__kart_cartitems', $items, "cart_item_id")) { echo $this->_db->stderr(); return -1; } // If updating from the checkout view then delete current cart entry. // If just updated cart entry and update cart entry is same then don't delete the entry. (in case of qty update) if (!empty($cart_item_id) && $cart_item_id != $items->cart_item_id) { $this->remove_cart($cart_item_id); } } else { // Else add update while updating the cart $minmax = $comquick2cartHelper->getMinMax($item_details['item_id']); if (!empty($minmax['min_quantity']) && !empty($minmax['max_quantity'])) { if ($item_details['count'] < $minmax['min_quantity'] || $item_details['count'] > $minmax['max_quantity']) { return JText::sprintf('COM_QUICK2CART_MIN_MAX_ERROR_SUD_BE_INRANGE', $minmax['min_quantity'], $minmax['max_quantity']); ""; } } $slabquantity = $item_details['count'] % $minmax['slab']; if ($slabquantity != 0) { return JText::sprintf('COM_QUICK2CART_QUANTITY_SHOULD_BE_MULI_OF_SLAB', $minmax['slab']); } $items->cart_id = $c_id; $items->item_id = $item_details['item_id']; $items->product_quantity = $item_details['count']; $items->order_item_name = $item_details['name']; $items->cdate = $timestamp; $dbAction = 'insertObject'; $action = 'insert'; if (!empty($cart_item_id)) { // Primary key = cart_item_id $items->cart_item_id = $cart_item_id; $dbAction = 'updateObject'; $action = 'update'; } if (!$this->_db->{$dbAction}('#__kart_cartitems', $items, 'cart_item_id')) { echo $this->_db->stderr(); return -1; } $insertOrUpdateRowId = $items->cart_item_id; if ($item_options) { $this->addEntryInCartItemAttributes($item_options, $insertOrUpdateRowId, $action); //~ foreach ($item_options as $item_option) //~ { //~ $items_opt = new stdClass; //~ $items_opt->cart_item_id = $items->cart_item_id; //~ $items_opt->itemattributeoption_id = $item_option['itemattributeoption_id']; //~ $items_opt->cartitemattribute_name = $item_option['itemattributeoption_name']; //~ $items_opt->cartitemattribute_price = $item_option['optionprice']; //~ $items_opt->cartitemattribute_prefix = $item_option['itemattributeoption_prefix']; //~ //~ if (!$this->_db->insertObject('#__kart_cartitemattributes', $items_opt, 'cartitemattribute_id')) //~ { //~ echo $this->_db->stderr(); //~ //~ return -1; //~ } //~ } } } return 1; }