Exemple #1
0
 public function addProductToCart($data = array())
 {
     JPluginHelper::importPlugin('redshop_product');
     $dispatcher = JDispatcher::getInstance();
     $rsUserhelper = new rsUserhelper();
     $redTemplate = new Redtemplate();
     $user = JFactory::getUser();
     $cart = $this->_session->get('cart');
     if (!$cart || !array_key_exists("idx", $cart) || array_key_exists("quotation_id", $cart)) {
         $cart = array();
         $cart['idx'] = 0;
     }
     $idx = (int) $cart['idx'];
     $section = isset($data['giftcard_id']) && $data['giftcard_id'] != 0 ? 13 : 12;
     $row_data = $this->_extraFieldFront->getSectionFieldList($section);
     // Set session for giftcard
     if (isset($data['giftcard_id']) && $data['giftcard_id']) {
         $cart[$idx]['reciver_email'] = $data['reciver_email'];
         $cart[$idx]['reciver_name'] = $data['reciver_name'];
         $cart[$idx]['customer_amount'] = $data['customer_amount'];
         for ($g = 0; $g < count($idx); $g++) {
             if ($cart[$g]['giftcard_id'] == $data['giftcard_id']) {
                 $cart[$idx]['quantity'] += 1;
                 $this->_session->set('cart', $cart);
                 return true;
             }
         }
         $cart[$idx]['quantity'] = 1;
         $giftcardData = $this->_producthelper->getGiftcardData($data['giftcard_id']);
         if ($giftcardData->customer_amount) {
             $giftcard_price = $data['customer_amount'];
         } else {
             $giftcard_price = $giftcardData->giftcard_price;
         }
         $cart[$idx]['product_price'] = $giftcard_price;
         $cart[$idx]['product_price_excl_vat'] = $giftcard_price;
         $cart[$idx]['product_vat'] = 0;
         $cart[$idx]['product_id'] = '';
         if (!$cart['discount_type']) {
             $cart['discount_type'] = 0;
         }
         if (!$cart['discount']) {
             $cart['discount'] = 0;
         }
         $cart[$idx]['giftcard_id'] = $data['giftcard_id'];
         for ($i = 0; $i < count($row_data); $i++) {
             $data_txt = isset($data[$row_data[$i]->field_name]) ? $data[$row_data[$i]->field_name] : '';
             $tmpstr = strpbrk($data_txt, '`');
             if ($tmpstr) {
                 $tmparray = explode('`', $data_txt);
                 $tmp = new stdClass();
                 $tmp = @array_merge($tmp, $tmparray);
                 if (is_array($tmparray)) {
                     $data_txt = implode(",", $tmparray);
                 }
             }
             $cart[$idx][$row_data[$i]->field_name] = $data_txt;
         }
         $cart['idx'] = $idx + 1;
         $this->_session->set('cart', $cart);
         return true;
     }
     if (isset($data['hidden_attribute_cartimage'])) {
         $cart[$idx]['hidden_attribute_cartimage'] = $data['hidden_attribute_cartimage'];
     }
     $product_id = $data['product_id'];
     $quantity = $data['quantity'];
     $product_data = $this->_producthelper->getProductById($product_id);
     if (isset($data['parent_accessory_product_id']) && $data['parent_accessory_product_id'] != 0) {
         $tempdata = $this->_producthelper->getProductById($data['parent_accessory_product_id']);
         $producttemplate = $redTemplate->getTemplate("product", $tempdata->product_template);
         $accessory_template = $this->_producthelper->getAccessoryTemplate($producttemplate[0]->template_desc);
         $data_add = $accessory_template->template_desc;
     } else {
         $producttemplate = $redTemplate->getTemplate("product", $product_data->product_template);
         $data_add = $producttemplate[0]->template_desc;
     }
     /*
      * Check if required userfield are filled or not if not than redirect to product detail page...
      * get product userfield from selected product template...
      */
     if (!AJAX_CART_BOX) {
         $fieldreq = $this->userfieldValidation($data, $data_add, $section);
         if ($fieldreq != "") {
             return $fieldreq;
         }
     }
     // Get product price
     $data['product_price'] = 0;
     // Attribute price added
     $generateAttributeCart = isset($data['cart_attribute']) ? $data['cart_attribute'] : $this->generateAttributeArray($data);
     $retAttArr = $this->_producthelper->makeAttributeCart($generateAttributeCart, $product_data->product_id, 0, $data['product_price'], $quantity);
     $selectProp = $this->_producthelper->getSelectedAttributeArray($data);
     $data['product_old_price'] = $retAttArr[5] + $retAttArr[6];
     $data['product_old_price_excl_vat'] = $retAttArr[5];
     $data['product_price'] = $retAttArr[1];
     $product_vat_price = $retAttArr[2];
     $cart[$idx]['product_price_excl_vat'] = $retAttArr[1];
     $data['product_price'] += $product_vat_price;
     if (!empty($selectProp[0])) {
         $attributeImage = $product_id;
         if (count($selectProp[0]) == 1) {
             $attributeImage .= '_p' . $selectProp[0][0];
         } else {
             $pattributeImage = implode('_p', $selectProp[0]);
             $attributeImage .= '_p' . $pattributeImage;
         }
         if (count($selectProp[1]) == 1) {
             $attributeImage .= '_sp' . $selectProp[1][0];
         } else {
             $sattributeImage = implode('_sp', $selectProp[1]);
             if ($sattributeImage) {
                 $attributeImage .= '_sp' . $sattributeImage;
             }
         }
         $cart[$idx]['attributeImage'] = $attributeImage . '.png';
     }
     if (!empty($data['reorder']) && !empty($data['attributeImage'])) {
         $cart[$idx]['attributeImage'] = $data['attributeImage'];
     }
     $selectedAttrId = $retAttArr[3];
     $isStock = $retAttArr[4];
     $selectedPropId = $selectProp[0];
     $notselectedSubpropId = $retAttArr[8];
     $product_preorder = $product_data->preorder;
     $isPreorderStock = $retAttArr[7];
     if (!$isStock) {
         if ($product_preorder == "global" && !ALLOW_PRE_ORDER || $product_preorder == "no" || $product_preorder == "" && !ALLOW_PRE_ORDER) {
             $msg = urldecode(JText::_('COM_REDSHOP_PRODUCT_OUTOFSTOCK_MESSAGE'));
             return $msg;
         } elseif (!$isPreorderStock) {
             $msg = urldecode(JText::_('COM_REDSHOP_PREORDER_PRODUCT_OUTOFSTOCK_MESSAGE'));
             return $msg;
         }
     }
     // Attribute End
     // Discount calculator procedure start
     $discountArr = array();
     $discountArr = $this->discountCalculatorData($product_data, $data);
     $calc_output = "";
     $calc_output_array = array();
     $product_price_tax = 0;
     if (!empty($discountArr)) {
         $calc_output = $discountArr[0];
         $calc_output_array = $discountArr[1];
         // Calculate price without VAT
         $data['product_price'] += $discountArr[2] + $discountArr[3];
         $cart[$idx]['product_price_excl_vat'] += $discountArr[2];
         $product_vat_price += $discountArr[3];
         $cart[$idx]['discount_calc_price'] = $discountArr[2];
     }
     $cart[$idx]['subscription_id'] = 0;
     if ($product_data->product_type == 'subscription') {
         if (isset($data['subscription_id']) && $data['subscription_id'] != "") {
             $subscription_detail = $this->_producthelper->getProductSubscriptionDetail($data['product_id'], $data['subscription_id']);
             $subscription_price = $subscription_detail->subscription_price;
             if ($subscription_price) {
                 $subscription_vat = $this->_producthelper->getProductTax($data['product_id'], $subscription_price);
             }
             $product_vat_price += $subscription_vat;
             $data['product_price'] = $data['product_price'] + $subscription_price + $subscription_vat;
             $data['product_old_price'] = $data['product_old_price'] + $subscription_price + $subscription_vat;
             $data['product_old_price_excl_vat'] += $subscription_price;
             $cart[$idx]['product_price_excl_vat'] += $subscription_price;
             $cart[$idx]['subscription_id'] = $data['subscription_id'];
         } else {
             $msg = urldecode(JText::_('COM_REDSHOP_PLEASE_SELECT_YOUR_SUBSCRIPTION_PLAN'));
             return $msg;
         }
     }
     // Accessory price
     if (ACCESSORY_AS_PRODUCT_IN_CART_ENABLE) {
         if (isset($data['accessory_data'])) {
             $cart['AccessoryAsProduct'] = array($data['accessory_data'], $data['acc_quantity_data'], $data['acc_attribute_data'], $data['acc_property_data'], $data['acc_subproperty_data']);
         }
         $generateAccessoryCart = array();
         $data['accessory_data'] = "";
         $data['acc_quantity_data'] = "";
         $data['acc_attribute_data'] = "";
         $data['acc_property_data'] = "";
         $data['acc_subproperty_data'] = "";
     } else {
         $generateAccessoryCart = isset($data['cart_accessory']) ? $data['cart_accessory'] : $this->generateAccessoryArray($data);
         if (isset($data['accessory_data']) && ($data['accessory_data'] != "" && $data['accessory_data'] != 0)) {
             if (!$generateAccessoryCart) {
                 $document = JFactory::getDocument();
                 return $document->getError();
             }
         }
     }
     $retAccArr = $this->_producthelper->makeAccessoryCart($generateAccessoryCart, $product_data->product_id);
     $accessory_total_price = $retAccArr[1];
     $accessory_vat_price = $retAccArr[2];
     $cart[$idx]['product_price_excl_vat'] += $accessory_total_price;
     $data['product_price'] += $accessory_total_price + $accessory_vat_price;
     $data['product_old_price'] += $accessory_total_price + $accessory_vat_price;
     $data['product_old_price_excl_vat'] += $accessory_total_price;
     $cart[$idx]['product_vat'] = $product_vat_price + $accessory_vat_price;
     if (!INDIVIDUAL_ADD_TO_CART_ENABLE) {
         /*
          * Check if required attribute is filled or not ...
          */
         $attribute_template = $this->_producthelper->getAttributeTemplate($data_add);
         if (count($attribute_template) > 0) {
             $selectedAttributId = 0;
             if (count($selectedAttrId) > 0) {
                 $selectedAttributId = implode(",", $selectedAttrId);
             }
             $req_attribute = $this->_producthelper->getProductAttribute($data['product_id'], 0, 0, 0, 1, $selectedAttributId);
             if (count($req_attribute) > 0) {
                 $requied_attributeArr = array();
                 for ($re = 0; $re < count($req_attribute); $re++) {
                     $requied_attributeArr[$re] = urldecode($req_attribute[$re]->attribute_name);
                 }
                 $requied_attribute_name = implode(", ", $requied_attributeArr);
                 // Throw an error as first attribute is required
                 $msg = urldecode($requied_attribute_name) . " " . JText::_('COM_REDSHOP_IS_REQUIRED');
                 return $msg;
             }
             $selectedPropertyId = 0;
             if (count($selectedPropId) > 0) {
                 $selectedPropertyId = implode(",", $selectedPropId);
             }
             $notselectedSubpropertyId = 0;
             if (count($notselectedSubpropId) > 0) {
                 $notselectedSubpropertyId = implode(",", $notselectedSubpropId);
             }
             $req_property = $this->_producthelper->getAttibuteProperty($selectedPropertyId, $selectedAttributId, $data['product_id'], 0, 1, $notselectedSubpropertyId);
             if (count($req_property) > 0) {
                 $requied_subattributeArr = array();
                 for ($re1 = 0; $re1 < count($req_property); $re1++) {
                     $requied_subattributeArr[$re1] = urldecode($req_property[$re1]->property_name);
                 }
                 $requied_subattribute_name = implode(",", $requied_subattributeArr);
                 // Give error as second attribute is required
                 $msg = urldecode($requied_subattribute_name) . " " . JText::_('COM_REDSHOP_SUBATTRIBUTE_IS_REQUIRED');
                 if ($data['reorder'] != 1) {
                     return $msg;
                 }
             }
         }
     }
     // ADD WRAPPER PRICE
     $wrapper_price = 0;
     $wrapper_vat = 0;
     if (isset($data['sel_wrapper_id']) && $data['sel_wrapper_id']) {
         $wrapperArr = $this->getWrapperPriceArr(array('product_id' => $data['product_id'], 'wrapper_id' => $data['sel_wrapper_id']));
         $wrapper_vat = $wrapperArr['wrapper_vat'];
         $wrapper_price = $wrapperArr['wrapper_price'];
     }
     $cart[$idx]['product_vat'] += $wrapper_vat;
     $data['product_price'] += $wrapper_price + $wrapper_vat;
     $data['product_old_price'] += $wrapper_price + $wrapper_vat;
     $data['product_old_price_excl_vat'] += $wrapper_price;
     $cart[$idx]['product_price_excl_vat'] += $wrapper_price;
     // END WRAPPER PRICE
     $att_id_total = false;
     $att_acc_total = false;
     $prodcut_id_total = false;
     // Checking For same Product and update Quantity
     $selectAcc = $this->_producthelper->getSelectedAccessoryArray($data);
     $selectAtt = $this->_producthelper->getSelectedAttributeArray($data);
     $sameProduct = false;
     for ($i = 0; $i < $idx; $i++) {
         if ($cart[$i]['product_id'] == $data['product_id']) {
             $sameProduct = true;
             if (isset($data['subscription_id']) && $cart[$i]['subscription_id'] != $data['subscription_id']) {
                 $sameProduct = false;
             }
             if ($cart[$i]['wrapper_id'] != $data['sel_wrapper_id']) {
                 $sameProduct = false;
             }
             $prevSelectAtt = $this->getSelectedCartAttributeArray($cart[$i]['cart_attribute']);
             $newdiff1 = array_diff($prevSelectAtt[0], $selectAtt[0]);
             $newdiff2 = array_diff($selectAtt[0], $prevSelectAtt[0]);
             if (count($newdiff1) > 0 || count($newdiff2) > 0) {
                 $sameProduct = false;
             }
             $newdiff1 = array_diff($prevSelectAtt[1], $selectAtt[1]);
             $newdiff2 = array_diff($selectAtt[1], $prevSelectAtt[1]);
             if (count($newdiff1) > 0 || count($newdiff2) > 0) {
                 $sameProduct = false;
             }
             $prevSelectAcc = $this->getSelectedCartAccessoryArray($cart[$i]['cart_accessory']);
             $newdiff1 = array_diff($prevSelectAcc[0], $selectAcc[0]);
             $newdiff2 = array_diff($selectAcc[0], $prevSelectAcc[0]);
             if (count($newdiff1) > 0 || count($newdiff2) > 0) {
                 $sameProduct = false;
             }
             $newdiff1 = array_diff($prevSelectAcc[1], $selectAcc[1]);
             $newdiff2 = array_diff($selectAcc[1], $prevSelectAcc[1]);
             if (count($newdiff1) > 0 || count($newdiff2) > 0) {
                 $sameProduct = false;
             }
             $newdiff1 = array_diff($prevSelectAcc[2], $selectAcc[2]);
             $newdiff2 = array_diff($selectAcc[2], $prevSelectAcc[2]);
             if (count($newdiff1) > 0 || count($newdiff2) > 0) {
                 $sameProduct = false;
             }
             // Discount calculator
             $array_diff_calc = array_diff_assoc($cart[$i]['discount_calc'], $calc_output_array);
             if (count($array_diff_calc) > 0) {
                 $sameProduct = false;
             }
             /**
              * Previous comment stated it is not used anymore.
              * Changing it for another purpose. It can intercept and decide whether added product should be added as same or new product.
              */
             $dispatcher->trigger('checkSameCartProduct', array(&$cart, $data, &$sameProduct));
             // Product userfiled
             if (!empty($row_data)) {
                 $puf = 1;
                 for ($r = 0; $r < count($row_data); $r++) {
                     $produser_field = $row_data[$r]->field_name;
                     $added_userfield = $data[$produser_field];
                     if (isset($cart[$i][$produser_field]) && $added_userfield != $cart[$i][$produser_field]) {
                         $puf = 0;
                     }
                 }
                 if ($puf != 1) {
                     $sameProduct = false;
                 }
             }
             if ($sameProduct) {
                 $newQuantity = $cart[$i]['quantity'] + $data['quantity'];
                 $newcartquantity = $this->checkQuantityInStock($cart[$i], $newQuantity);
                 if ($newQuantity > $newcartquantity) {
                     $cart['notice_message'] = $newcartquantity . " " . JTEXT::_('COM_REDSHOP_AVAILABLE_STOCK_MESSAGE');
                 } else {
                     $cart['notice_message'] = "";
                 }
                 if ($newcartquantity != $cart[$i]['quantity']) {
                     $cart[$i]['quantity'] = $newcartquantity;
                     /*
                      * trigger the event of redSHOP product plugin support on Same product is going to add into cart
                      *
                      * Usually redSHOP update quantity
                      */
                     $dispatcher->trigger('onSameCartProduct', array(&$cart, $data, $i));
                     $this->_session->set('cart', $cart);
                     $data['cart_index'] = $i;
                     $data['quantity'] = $newcartquantity;
                     $this->update($data);
                     return true;
                 } else {
                     $msg = CART_RESERVATION_MESSAGE != '' && IS_PRODUCT_RESERVE ? CART_RESERVATION_MESSAGE : urldecode(JText::_('COM_REDSHOP_PRODUCT_OUTOFSTOCK_MESSAGE'));
                     return $msg;
                 }
             }
         }
     }
     // Set product price
     if ($data['product_price'] < 0) {
         $data['product_price'] = 0;
     }
     $per_product_total = $product_data->minimum_per_product_total;
     if ($data['product_price'] < $per_product_total) {
         $msg = JText::_('COM_REDSHOP_PER_PRODUCT_TOTAL') . " " . $per_product_total;
         return $msg;
     }
     if (!$sameProduct) {
         // SET VALVUES INTO SESSION CART
         $cart[$idx]['giftcard_id'] = '';
         $cart[$idx]['product_id'] = $data['product_id'];
         $cart[$idx]['discount_calc_output'] = $calc_output;
         $cart[$idx]['discount_calc'] = $calc_output_array;
         $cart[$idx]['product_price'] = $data['product_price'];
         $cart[$idx]['product_old_price'] = $data['product_old_price'];
         $cart[$idx]['product_old_price_excl_vat'] = $data['product_old_price_excl_vat'];
         $cart[$idx]['cart_attribute'] = $generateAttributeCart;
         $cart[$idx]['cart_accessory'] = $generateAccessoryCart;
         if (isset($data['hidden_attribute_cartimage'])) {
             $cart[$idx]['hidden_attribute_cartimage'] = $data['hidden_attribute_cartimage'];
         }
         $cart[$idx]['quantity'] = 0;
         $newQuantity = $data['quantity'];
         $cart[$idx]['quantity'] = $this->checkQuantityInStock($cart[$idx], $newQuantity);
         if ($newQuantity > $cart[$idx]['quantity']) {
             $cart['notice_message'] = $cart[$idx]['quantity'] . " " . JTEXT::_('COM_REDSHOP_AVAILABLE_STOCK_MESSAGE');
         } else {
             $cart['notice_message'] = "";
         }
         if ($cart[$idx]['quantity'] <= 0) {
             $msg = CART_RESERVATION_MESSAGE != '' && IS_PRODUCT_RESERVE ? CART_RESERVATION_MESSAGE : JText::_('COM_REDSHOP_PRODUCT_OUTOFSTOCK_MESSAGE');
             return $msg;
         }
         $cart[$idx]['category_id'] = $data['category_id'];
         $cart[$idx]['wrapper_id'] = $data['sel_wrapper_id'];
         $cart[$idx]['wrapper_price'] = $wrapper_price + $wrapper_vat;
         /**
          * Implement new plugin support before session update
          * trigger the event of redSHOP product plugin support on Before cart session is set - on prepare cart session
          */
         $dispatcher->trigger('onBeforeSetCartSession', array(&$cart, $data));
         $cart['idx'] = $idx + 1;
         for ($i = 0; $i < count($row_data); $i++) {
             $field_name = $row_data[$i]->field_name;
             $data_txt = isset($data[$field_name]) ? $data[$field_name] : '';
             $tmpstr = strpbrk($data_txt, '`');
             if ($tmpstr) {
                 $data_txt = str_replace('`', ',', $data_txt);
             }
             $cart[$idx][$field_name] = $data_txt;
         }
     }
     if (!$cart['discount_type']) {
         $cart['discount_type'] = 0;
     }
     if (!$cart['discount']) {
         $cart['discount'] = 0;
     }
     if (!$cart['cart_discount']) {
         $cart['cart_discount'] = 0;
     }
     if (!isset($cart['user_shopper_group_id']) || isset($cart['user_shopper_group_id']) && $cart['user_shopper_group_id'] == 0) {
         $cart['user_shopper_group_id'] = $rsUserhelper->getShopperGroup($user->id);
     }
     $cart['free_shipping'] = 0;
     $this->_session->set('cart', $cart);
     return true;
 }
 public function setQuotationMode()
 {
     $user = JFactory::getUser();
     $userhelper = new rsUserhelper();
     $shopper_group_id = SHOPPER_GROUP_DEFAULT_UNREGISTERED;
     if ($user->id) {
         $getShopperGroupID = $userhelper->getShopperGroup($user->id);
         if ($getShopperGroupID) {
             $shopper_group_id = $getShopperGroupID;
         }
     }
     $qurey = "SELECT * FROM " . $this->_table_prefix . "shopper_group " . "WHERE shopper_group_id = " . (int) $shopper_group_id;
     $this->_db->setQuery($qurey);
     $list = $this->_db->loadObject();
     if ($list) {
         if ($list->shopper_group_quotation_mode) {
             return 1;
         } else {
             return 0;
         }
     } else {
         return DEFAULT_QUOTATION_MODE_PRE;
     }
 }
Exemple #3
0
$order = $order_functions->getOrderDetails($request['order_id']);
$paymentinfo = $getparameters[0];
$paymentparams = new JRegistry($paymentinfo->params);
$is_creditcard = $paymentparams->get('is_creditcard', '');
$payment_oprand = $paymentparams->get('payment_oprand', '');
$payment_discount_is_percent = $paymentparams->get('payment_discount_is_percent', '');
$payment_price = $paymentparams->get('payment_price', '');
$accepted_credict_card = $paymentparams->get("accepted_credict_card");
$paymentinfo = new stdclass();
$paymentinfo->payment_price = $payment_price;
$paymentinfo->is_creditcard = $is_creditcard;
$paymentinfo->payment_oprand = $payment_oprand;
$paymentinfo->payment_discount_is_percent = $payment_discount_is_percent;
$paymentinfo->accepted_credict_card = $accepted_credict_card;
$order_shipping_rate = $cart['shipping'];
$shopperGroupId = $userhelper->getShopperGroup($user_id);
if (PAYMENT_CALCULATION_ON == 'subtotal') {
    $paymentAmount = $cart['product_subtotal'];
} else {
    $paymentAmount = $cart['total'];
}
$paymentArray = $carthelper->calculatePayment($paymentAmount, $paymentinfo, $paymentAmount);
$total = $paymentArray[0];
$payment_amount = $paymentArray[1];
?>
	<!-- <hr/>
<table width="100%" border="0" cellspacing="2" cellpadding="2" >
<tr><td width="33%" class="checkout-bar-1"><?php 
echo JText::_('COM_REDSHOP_ORDER_INFORMATION');
?>
</td>