/** * addToCartAPI * ( * [itemattributeoption_id] => 89 * [type] => Textbox * [value] => Techjoomla * ) ) * * @param STRING $item Array ( [id] => 5 * [parent] => com_quick2cart // cliend * [count] => 1 // qty * [options] => 89,91 ) * @param STRING $userData Array ([89] => Array // 89 is attribute option id * ( * [itemattributeoption_id] => 89 * [type] => Textbox * [value] => vm * ) * * @return STRING. * * @since 1.6 */ public function addToCartAPI($item, $userData) { // Load cart model $path = JPATH_SITE . "/components/com_quick2cart/models/cart.php"; $this->loadqtcClass($path, 'Quick2cartModelcart'); $Quick2cartModelcart = new Quick2cartModelcart(); // Makre cart $cartId = $Quick2cartModelcart->makeCart(); // TART Q2C Sample development $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('system'); $result = $dispatcher->trigger('OnBeforeq2cAdd2Cart', array($cartId, $item)); if (!empty($result)) { $item_obj = $result[0]; } if (!empty($item_obj)) { if ($item_obj[0] == false) { // $msg['success'] = FALSE; $msg['message'] = $item_obj[1]; // Return json_encode($msg); // As we r encoding in main controller return $msg; } else { $item = $item_obj[1]; } } // END Q2C Sample development // Get Current item details. $prod_details = $Quick2cartModelcart->getProd($item); if (empty($item['params'])) { $item['params'] = ''; } // If option present if (!empty($prod_details[1])) { // Add user field detail to options $AttrOptions = $prod_details[1]; $prod_details[1] = $this->AddUserFieldDetail($AttrOptions, $userData); } // Put item detail to cart $result = $Quick2cartModelcart->putCartitem($cartId, $prod_details, $item['params']); // Validate Result. If added successfully. if (is_numeric($result) && $result == 1) { $msg['status'] = true; $msg['successCode'] = 1; $params = JComponentHelper::getParams('com_quick2cart'); $popup_buynow = $params->get('popup_buynow', 1); // TO OPEN SMALL POP UP - if ($popup_buynow == 2) { // $product_name = $item['id']; $item_count = $Quick2cartModelcart->countCartitems(); $msg['message'] = JText::sprintf('COM_QUICK2CART_COMPACT_MSG', $prod_details[0]['name'], $item_count); } } elseif (is_numeric($result) && $result == 2) { // Single store checkout is enabled and try to buy the product from other store. $msg['successCode'] = 2; $msg['status'] = false; $msg['message'] = JText::_('COM_QUICK2CART_SINGLE_STORE_CKOUT_ALLOWED'); } else { $msg['successCode'] = 0; $msg['success'] = false; $msg['message'] = $result; } return $msg; }
/** * Function: updatecart updates the cart and also calculates the tax and shipping charges * * @return json * * @since 1.0.0 */ public function update_cart_item() { $comquick2cartHelper = new comquick2cartHelper(); $input = JFactory::getApplication()->input; $post = $input->post; $data = $post->get('formData', '', 'STRING'); $cart_item_id = $post->get('cart_item_id', '', 'INT'); $item_id = $post->get('item_id', '', 'INT'); // Get parsed form data parse_str($post->get('formData', '', 'STRING'), $formData); // Load cart model /*$item = Array ( [id] => 17 [parent] => com_quick2cart [item_id] => 8 if item_id present then no need of id and parent fields [count] => 1 [options] => 24,23,22,19 ) <pre>$userdata = Array ( [23] => Array ( [itemattributeoption_id] => 23 [type] => Textbox [value] => qqq ) [24] => Array ( [itemattributeoption_id] => 24 [type] => Textbox [value] => www ) ) * */ $itemFromattedDet = array(); $itemFromattedDet['item_id'] = $item_id; $userdata = array(); if (!empty($formData['cartDetail']) && !empty($cart_item_id)) { $newItemDetails = $formData['cartDetail'][$cart_item_id]; $itemFromattedDet['count'] = $newItemDetails['cart_count']; $itemFromattedDet['options'] = ''; // If not empty attribute details if (!empty($newItemDetails['attrDetail'])) { $attrDetail = $newItemDetails['attrDetail']; foreach ($attrDetail as $key => $attr) { if ($attr['type'] == 'Textbox' && !empty($attr['value'])) { $userkey = $attr['itemattributeoption_id']; $userdata[$userkey] = $attr; $itemFromattedDet['options'] .= $attr['itemattributeoption_id'] . ','; } else { $itemFromattedDet['options'] .= $attr['value'] . ','; } } } } $path = JPATH_SITE . "/components/com_quick2cart/models/cart.php"; $comquick2cartHelper->loadqtcClass($path, 'Quick2cartModelcart'); $Quick2cartModelcart = new Quick2cartModelcart(); // Remove last comma if (!empty($itemFromattedDet['options'])) { $tempArray = explode(',', $itemFromattedDet['options']); $tempArray = array_filter($tempArray, "strlen"); $itemFromattedDet['options'] = implode(',', $tempArray); } // Get formated product details (internal) $prod_details = $Quick2cartModelcart->getProd($itemFromattedDet); // If option present if (!empty($prod_details[1])) { // Add user field detail to options $AttrOptions = $prod_details[1]; $prod_details[1] = $comquick2cartHelper->AddUserFieldDetail($AttrOptions, $userdata); } // Update the cart $result = $Quick2cartModelcart->putCartitem('', $prod_details, $cart_item_id); // Validate Result. If added successfully. if (is_numeric($result) && $result == 1) { $msg['status'] = true; $msg['successCode'] = 1; //$msg['message'] = JText::sprintf('COM_QUICK2CART_COMPACT_MSG', $prod_details[0]['name'], $item_count); } else { $msg['status'] = false; $msg['successCode'] = 0; $msg['message'] = $result; } echo json_encode($msg); jexit(); }