Example #1
0
 /**
  * This function used to show product's detail's and allow to buy.
  *
  * @param   integer  $pId            product id.
  * @param   string   $parent         client eg com_content etc.
  * @param   array    $qtcExtraParam  eg array('hideFreeDdownloads'=>true,'hideOriginalPrice'=>true,
  * 										'hideDiscountPrice'=>true,'hideAttributes'=>true)
  *
  * @return  html.
  *
  * @since   1.6
  */
 public function getBuynow($pId, $parent, $qtcExtraParam = array())
 {
     // LOAD product HELPER
     $path = JPATH_SITE . '/components/com_quick2cart/helpers/product.php';
     if (!class_exists('productHelper')) {
         // Require_once $path;
         JLoader::register('productHelper', $path);
         JLoader::load('productHelper');
     }
     // Require_once (JPATH_SITE . '/components/com_quick2cart/models/cart.php');
     $app = JFactory::getApplication();
     $html = '';
     JLoader::register("quick2cartViewcart", JPATH_SITE . "/components/com_quick2cart/views/cart/view.html.php");
     $layout = 'pushtocart';
     $view = new quick2cartViewcart();
     // $view->_basePath = JPATH_ROOT . '/components/com_quick2cart';
     $view->addTemplatePath(JPATH_SITE . '/components/com_quick2cart/views/cart/tmpl');
     $view->addTemplatePath(JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_quick2cart/cart');
     // JModel::addIncludePath(JPATH_SITE . '/components/com_quick2cart/models/cart.php');
     $comparams = JComponentHelper::getParams('com_quick2cart');
     JLoader::import('cart', JPATH_SITE . '/components/com_quick2cart/models');
     $model = new Quick2cartModelcart();
     // $item_id = $model->getitemid($pId, $parent);
     $itemidAndState = $model->getitemidAndState($pId, $parent);
     // # if entry is not present in kart_item
     if (empty($itemidAndState['item_id']) || empty($itemidAndState['state'])) {
         return false;
     }
     $item_id = $itemidAndState['item_id'];
     // Return array of price
     $price = $model->getPrice($item_id, 1);
     $itemAttrDetail = $model->getItemCompleteAttrDetail($item_id);
     $comquick2cartHelper = new comquick2cartHelper();
     $productHelper = new productHelper();
     $hasprice = $this->hasAttributePrice($itemAttrDetail);
     // Get free products media file
     $mediaFiles = $productHelper->getProdmediaFiles($item_id);
     $orderWithZeroPrice = $comparams->get('orderWithZeroPrice', 0);
     $qtcShowBuyNow = 0;
     if ($orderWithZeroPrice == 0 && ($price > 0 && $hasprice)) {
         // Product final price has some price and attribute has currency values
         $qtcShowBuyNow = 1;
     }
     $view->assign('price', $price);
     $view->assign('_basePath', JPATH_SITE . '/components/com_quick2cart');
     $view->set('_controller', 'cart');
     $view->set('_view', 'cart');
     $view->set('_doTask', true);
     $view->set('hidemenu', true);
     $view->setModel($model, true);
     $view->setLayout($layout);
     $itemdetail = $model->getItemRec($item_id);
     $showBuyNowBtn = $productHelper->isInStockProduct($itemdetail);
     $view->assign('showBuyNowBtn', $showBuyNowBtn);
     $view->assign('stock', $itemdetail->stock);
     $view->assign('min_quantity', $itemdetail->min_quantity);
     $view->assign('max_quantity', $itemdetail->max_quantity);
     $view->assign('slab', $itemdetail->slab);
     $view->assign('product_id', $pId);
     $view->assign('parent', $parent);
     // Get attributes
     $attributes = $model->getAttributes($item_id);
     $view->assign('attributes', $attributes);
     $view->assign('mediaFiles', $mediaFiles);
     $view->assign('params', $comparams);
     $view->assign('qtcExtraParam', $qtcExtraParam);
     ob_start();
     $view->display();
     $html = ob_get_contents();
     ob_end_clean();
     return $html;
 }
Example #2
0
 function display($tpl = null)
 {
     $comquick2cartHelper = new comquick2cartHelper();
     $input = JFactory::getApplication()->input;
     $layout = $input->get('layout', 'default');
     $option = $input->get('option', '');
     $this->params = JFactory::getApplication()->getParams('com_quick2cart');
     // check for multivender COMPONENT PARAM
     // vm: commented for task #20773
     /*	$isMultivenderOFFmsg=$comquick2cartHelper->isMultivenderOFF();
     		if(!empty($isMultivenderOFFmsg))
     		{
     			print $isMultivenderOFFmsg;
     			return false;
     		}*/
     if ($layout == 'default') {
         // product page
         //DECLARATION SECTION
         $this->client = $client = "com_quick2cart";
         $this->pid = 0;
         $this->item_id = $item_id = $input->get('item_id', '');
         JLoader::import('cart', JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'models');
         $model = new Quick2cartModelcart();
         if (empty($item_id)) {
             // # if entry is not present in kart_item
             return false;
         }
         // retrun store_id,role etc with order by role,store_id
         $this->store_role_list = $comquick2cartHelper->getStoreIds();
         // GETTING AUTHORIZED STORE ID
         $storeHelper = new storeHelper();
         $this->store_list = $storeHelper->getuserStoreList();
         // GETTING PRICE
         $this->price = $price = $model->getPrice($item_id, 1);
         // return array of price
         //GETTING ITEM COMPLEATE DETAIL (attributes and its option wil get)
         //$itemDetail=$model->getItemCompleteDetail($item_id);
         //getting stock min max,cat,store_id
         $this->itemdetail = $model->getItemRec($item_id);
         if (!empty($this->itemdetail)) {
             ///get attributes
             $this->attributes = $model->getAttributes($item_id);
             // for RELEATED PROD FROM CATEGORY
             $product_path = JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'helpers' . DS . 'product.php';
             if (!class_exists('productHelper')) {
                 //require_once $path;
                 JLoader::register('productHelper', $product_path);
                 JLoader::load('productHelper');
             }
             $productHelper = new productHelper();
             // get free products media file
             $this->mediaFiles = $productHelper->getProdmediaFiles($item_id);
             $this->prodFromCat = $productHelper->getSimilarProdFromCat($this->itemdetail->category, $this->item_id);
             $this->prodFromSameStore = $productHelper->prodFromSameStore($this->itemdetail->store_id, $this->item_id);
             $this->peopleAlsoBought = $productHelper->peopleAlsoBought($this->item_id);
             $this->peopleWhoBought = $productHelper->peopleWhoBought($this->item_id);
             //print_r($this->peopleWhoBought);die;
             $social_options = '';
             $route = $comquick2cartHelper->getProductLink($this->item_id);
             // Jilke
             $dispatcher = JDispatcher::getInstance();
             JPluginHelper::importPlugin('system');
             $result = $dispatcher->trigger('onProductDisplaySocialOptions', array($this->item_id, 'com_quick2cart.productpage', $this->itemdetail->name, $route));
             //Call the plugin and get the result
             if (!empty($result)) {
                 $social_options = $result[0];
             }
             $this->social_options = $social_options;
             $this->showBuyNowBtn = $productHelper->isInStockProduct($this->itemdetail);
         }
     } elseif ($layout == 'popupslide') {
         $this->item_id = $item_id = $input->get('qtc_prod_id', '');
         JLoader::import('cart', JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'models');
         $model = new Quick2cartModelcart();
         if (empty($item_id)) {
             // # if entry is not present in kart_item
             return false;
         }
         $this->itemdetail = $model->getItemRec($item_id);
     }
     $this->item = $this->itemdetail;
     $this->_prepareDocument();
     parent::display($tpl);
 }
Example #3
0
 /**
  * $getOriginalPrice is set then product original price will be considered in calculation
  *
  */
 public function getCartitems($getOriginalPrice = 0)
 {
     $comquick2cartHelper = new comquick2cartHelper();
     $currency = $comquick2cartHelper->getCurrencySession();
     $db = JFactory::getDBO();
     //@TODO ask ashwin about this
     $Quick2cartModelcart = new Quick2cartModelcart();
     $cart_id = $Quick2cartModelcart->getCartId();
     if (!isset($cart_id)) {
         return;
     }
     $query = "Select k.cart_item_id as id, \tk.cart_id,k.store_id,i.sku,\n\t\t\t\t\tk.order_item_name as title,\tk.user_info_id,\n\t\t\t\t\tk.cdate,\t\t\t\t\t\tk.mdate,\n\t\t\t\t\tk.product_quantity as qty, \t\tk.product_attribute_names as options,\n\t\t\t\t\tk.item_id, k.product_item_price,k.product_attributes_price,k.product_final_price,k.original_price,k. params,currency,\n\t\t\t\t\tk.product_attributes\n\t\t FROM #__kart_cartitems as k,#__kart_items as i\n\t\t WHERE k.item_id=i.item_id and k.cart_id='{$cart_id}' order by k.`store_id`";
     $db->setQuery($query);
     $cart = $db->loadAssocList();
     foreach ($cart as $key => $rec) {
         $cart[$key]['seller_id'] = JFactory::getUser()->id;
         //@TODO fetch store owner from items table
         // task 1 fetch item price
         $pricearray = "";
         $return_disc = 0;
         $prod_price = $Quick2cartModelcart->getPrice($rec['item_id'], $return_disc, $getOriginalPrice);
         $cart[$key]['amt'] = $prod_price['price'];
         //product_item_price as amt
         // task 2 attribute price
         if (isset($rec['product_attributes']) && $rec['product_attributes']) {
             $totop_price = $Quick2cartModelcart->getCurrPriceFromBaseCurrencyOption($rec['product_attributes']);
             $cart[$key]['opt_amt'] = $totop_price;
             // product_attributes_price as opt_amt*/
         } else {
             $cart[$key]['opt_amt'] = 0;
             // product_attributes_price as opt_amt*/
         }
         // task 3 calculate total m price
         $cart[$key]['tamt'] = ((double) $cart[$key]['amt'] + (double) $cart[$key]['opt_amt']) * (double) $cart[$key]['qty'];
         //product_final_price as tamt
         //  synchronize new item price and its related in cart_item table
         $cart_item = new stdClass();
         $cart_item->cart_item_id = $cart[$key]['id'];
         //as id
         $cart_item->product_quantity = $cart[$key]['qty'];
         $cart_item->product_item_price = $cart[$key]['amt'];
         $cart_item->product_attributes_price = $cart[$key]['opt_amt'];
         if (!empty($rec['params'])) {
             $params = json_decode($rec['params'], true);
             JLoader::import('cartcheckout', JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'models');
             $Quick2cartModelcartcheckout = new Quick2cartModelcartcheckout();
             if (!empty($params['coupon_code'])) {
                 $coupon = $Quick2cartModelcartcheckout->getcoupon($params['coupon_code']);
                 $coupon = $coupon ? $coupon : array();
                 if (isset($coupon) && $coupon) {
                     if (in_array($cart[$key]['item_id'], $coupon[0]->item_id)) {
                         $camt = -1;
                         $cart[$key]['original_price'] = $cart[$key]['tamt'];
                         $cart_item->original_price = $cart[$key]['original_price'];
                         $coupon[0]->cop_code = $params['coupon_code'];
                         if ($coupon[0]->val_type == 1) {
                             $cval = $coupon[0]->value / 100 * $cart[$key]['tamt'];
                         } else {
                             $cval = $coupon[0]->value;
                             $cval = $cval * $cart[$key]['qty'];
                             /*multiply cop disc with qty*/
                         }
                         $camt = $cart[$key]['tamt'] - $cval;
                         if ($camt <= 0) {
                             $camt = 0;
                         }
                         $cart[$key]['tamt'] = !($camt == -1) ? $camt : $cart[$key]['tamt'];
                     }
                 }
             }
         }
         $cart_item->product_final_price = $cart[$key]['tamt'];
         $cart_item->currency = $comquick2cartHelper->getCurrencySession();
         $db = JFactory::getDBO();
         if ($cart_item->product_item_price != $cart[$key]['product_item_price'] || $cart_item->product_attributes_price != $cart[$key]['product_attributes_price'] || $cart_item->product_final_price != $cart[$key]['product_final_price'] || $cart_item->currency != $cart[$key]['currency']) {
             if (!$db->updateObject('#__kart_cartitems', $cart_item, "cart_item_id")) {
                 echo $this->_db->stderr();
                 return -1;
             }
         }
     }
     return $cart;
 }