Пример #1
0
 public function neworderitem()
 {
     $adminproducthelper = new adminproducthelper();
     $stockroomhelper = new rsstockroomhelper();
     $post = JRequest::get('post');
     $tmpl = "";
     if (isset($post['tmpl'])) {
         $tmpl = $post['tmpl'];
     }
     $option = JRequest::getVar('option', '', 'request', 'string');
     $cid = JRequest::getVar('cid', array(0), 'post', 'array');
     $order_item_id = JRequest::getVar('order_item_id', 0, 'post', '');
     $model = $this->getModel('order_detail');
     $orderItem = $adminproducthelper->redesignProductItem($post);
     $post['order_item'] = $orderItem;
     $product_id = $orderItem[0]->product_id;
     $finalquantity = $quantity = $orderItem[0]->quantity;
     // Check product Quantity
     if (USE_STOCKROOM == 1) {
         $currentStock = $stockroomhelper->getStockroomTotalAmount($product_id);
         if ($currentStock >= $quantity) {
             $finalquantity = (int) $quantity;
         } else {
             $finalquantity = (int) $currentStock;
         }
     }
     if ($finalquantity > 0) {
         if ($model->neworderitem($post, $finalquantity, $order_item_id)) {
             if ($order_item_id == 0) {
                 $msg = JText::_('COM_REDSHOP_ORDER_ITEM_ADDED');
             } else {
                 $msg = JText::_('COM_REDSHOP_QUANTITY_UPDATED');
             }
         } else {
             if ($order_item_id == 0) {
                 $msg = JText::_('COM_REDSHOP_ERROR_ADDING_ORDER_ITEM');
             } else {
                 $msg = JText::_('COM_REDSHOP_ERROR_UPDATING_QUANTITY');
             }
         }
     } else {
         $msg = JText::_('COM_REDSHOP_PRODUCT_OUT_OF_STOCK');
     }
     if ($tmpl) {
         $this->setRedirect('index.php?option=' . $option . '&view=order_detail&cid[]=' . $cid[0] . '&tmpl=' . $tmpl, $msg);
     } else {
         $this->setRedirect('index.php?option=' . $option . '&view=order_detail&cid[]=' . $cid[0], $msg);
     }
 }
Пример #2
0
 public function checkAttributeStockRoom($data = array(), $productData = array())
 {
     $stockroomhelper = new rsstockroomhelper();
     $newquantity = $data['quantity'];
     $attArr = $data['cart_attribute'];
     $product_preorder = $productData->preorder;
     for ($i = 0; $i < count($attArr); $i++) {
         $propArr = $attArr[$i]['attribute_childs'];
         for ($k = 0; $k < count($propArr); $k++) {
             if (USE_STOCKROOM == 1) {
                 if ($product_preorder == "global" && !ALLOW_PRE_ORDER || $product_preorder == "no" || $product_preorder == "" && !ALLOW_PRE_ORDER) {
                     $property_stock = $stockroomhelper->getStockroomTotalAmount($propArr[$k]['property_id'], "property");
                 }
                 if ($product_preorder == "global" && ALLOW_PRE_ORDER || $product_preorder == "yes" || $product_preorder == "" && ALLOW_PRE_ORDER) {
                     $regular_property_stock = $stockroomhelper->getStockroomTotalAmount($propArr[$k]['property_id'], "property");
                     $Preorder_property_stock = $stockroomhelper->getPreorderStockroomTotalAmount($propArr[$k]['property_id'], "property");
                     $property_stock = $regular_property_stock + $Preorder_property_stock;
                 }
                 $ownreserveStock = $stockroomhelper->getCurrentUserReservedStock($propArr[$k]['property_id'], "property");
                 if ($property_stock >= 0) {
                     if ($newquantity > $ownreserveStock && $property_stock < $newquantity - $ownreserveStock) {
                         $newquantity = $property_stock + $ownreserveStock;
                     }
                 } else {
                     $newquantity = $property_stock + $ownreserveStock;
                 }
             }
             $subpropArr = $propArr[$k]['property_childs'];
             for ($l = 0; $l < count($subpropArr); $l++) {
                 if (USE_STOCKROOM == 1) {
                     if ($product_preorder == "global" && !ALLOW_PRE_ORDER || $product_preorder == "no" || $product_preorder == "" && !ALLOW_PRE_ORDER) {
                         $subproperty_stock = $stockroomhelper->getStockroomTotalAmount($subpropArr[$l]['subproperty_id'], "subproperty");
                     }
                     if ($product_preorder == "global" && ALLOW_PRE_ORDER || $product_preorder == "yes" || $product_preorder == "" && ALLOW_PRE_ORDER) {
                         $regular_subproperty_stock = $stockroomhelper->getStockroomTotalAmount($subpropArr[$l]['subproperty_id'], "subproperty");
                         $preorder_subproperty_stock = $stockroomhelper->getPreorderStockroomTotalAmount($subpropArr[$l]['subproperty_id'], "subproperty");
                         $subproperty_stock = $regular_subproperty_stock + $preorder_subproperty_stock;
                     }
                     $ownreserveStock = $stockroomhelper->getCurrentUserReservedStock($propArr[$k]['property_id'], "property");
                     if ($subproperty_stock >= 0) {
                         if ($newquantity > $ownreserveStock && $subproperty_stock < $newquantity - $ownreserveStock) {
                             $newquantity = $subproperty_stock + $ownreserveStock;
                         }
                     } else {
                         $newquantity = $subproperty_stock + $ownreserveStock;
                     }
                 }
             }
         }
     }
     if ($productData->max_order_product_quantity > 0 && $productData->max_order_product_quantity < $newquantity) {
         $newquantity = $productData->max_order_product_quantity;
     }
     for ($i = 0; $i < count($attArr); $i++) {
         $propArr = $attArr[$i]['attribute_childs'];
         for ($k = 0; $k < count($propArr); $k++) {
             $stockroomhelper->addReservedStock($propArr[$k]['property_id'], $newquantity, "property");
             $subpropArr = $propArr[$k]['property_childs'];
             for ($l = 0; $l < count($subpropArr); $l++) {
                 $stockroomhelper->addReservedStock($subpropArr[$l]['subproperty_id'], $newquantity, "subproperty");
             }
         }
     }
     return $newquantity;
 }
Пример #3
0
 public function save($apply = 0)
 {
     $post = JRequest::get('post');
     $adminproducthelper = new adminproducthelper();
     $order_functions = new order_functions();
     $shippinghelper = new shipping();
     $option = JRequest::getVar('option', '', 'request', 'string');
     $cid = JRequest::getVar('cid', array(0), 'post', 'array');
     $post['order_id'] = $cid[0];
     $model = $this->getModel('addorder_detail');
     $post['order_number'] = $order_number = $order_functions->generateOrderNumber();
     $orderItem = $adminproducthelper->redesignProductItem($post);
     $post['order_item'] = $orderItem;
     // Check product Quantity
     $stocknote = '';
     if (USE_STOCKROOM == 1) {
         $stockroomhelper = new rsstockroomhelper();
         $producthelper = new producthelper();
         for ($i = 0; $i < count($orderItem); $i++) {
             $quantity = $orderItem[$i]->quantity;
             $productData = $producthelper->getProductById($orderItem[$i]->product_id);
             if ($productData->min_order_product_quantity > 0 && $productData->min_order_product_quantity > $quantity) {
                 $msg = $productData->product_name . " " . JText::_('WARNING_MSG_MINIMUM_QUANTITY');
                 $stocknote .= sprintf($msg, $productData->min_order_product_quantity) . "<br/>";
                 $quantity = $productData->min_order_product_quantity;
             }
             $currentStock = $stockroomhelper->getStockroomTotalAmount($orderItem[$i]->product_id);
             $finalquantity = $currentStock >= $quantity ? (int) $quantity : (int) $currentStock;
             if ($finalquantity > 0) {
                 if ($productData->max_order_product_quantity > 0 && $productData->max_order_product_quantity < $finalquantity) {
                     $msg = $productData->product_name . " " . JText::_('WARNING_MSG_MAXIMUM_QUANTITY') . "<br/>";
                     $stocknote .= sprintf($msg, $productData->max_order_product_quantity);
                     $finalquantity = $productData->max_order_product_quantity;
                 }
                 $orderItem[$i]->quantity = $finalquantity;
             } else {
                 $stocknote .= $productData->product_name . " " . JText::_('PRODUCT_OUT_OF_STOCK') . "<br/>";
                 unset($orderItem[$i]);
             }
         }
         $orderItem = array_merge(array(), $orderItem);
         if (count($orderItem) <= 0) {
             $msg = JText::_('PRODUCT_OUT_OF_STOCK');
             $this->setRedirect('index.php?option=' . $option . '&view=addorder_detail&user_id=' . $post['user_id'] . '&shipping_users_info_id=' . $post['shipp_users_info_id'], $msg);
             return;
         }
     }
     $order_total = $post['order_total'];
     $order_shipping = explode("|", $shippinghelper->decryptShipping(str_replace(" ", "+", $post['shipping_rate_id'])));
     if (count($order_shipping) > 4) {
         $post['order_shipping'] = $order_shipping[3];
         $order_total = $order_total + $order_shipping[3];
         $post['order_shipping_tax'] = $order_shipping[6];
     }
     $tmporder_total = $order_total;
     if (array_key_exists("issplit", $post) && $post['issplit']) {
         $tmporder_total = $order_total / 2;
     }
     $paymentmethod = $order_functions->getPaymentMethodInfo($post['payment_method_class']);
     $paymentmethod = $paymentmethod[0];
     $paymentparams = new JRegistry($paymentmethod->params);
     $paymentinfo = new stdclass();
     $post['economic_payment_terms_id'] = $paymentparams->get('economic_payment_terms_id');
     $post['economic_design_layout'] = $paymentparams->get('economic_design_layout');
     $paymentinfo->payment_price = $paymentparams->get('payment_price', '');
     $paymentinfo->is_creditcard = $post['economic_is_creditcard'] = $paymentparams->get('is_creditcard', '');
     $paymentinfo->payment_oprand = $paymentparams->get('payment_oprand', '');
     $paymentinfo->accepted_credict_card = $paymentparams->get("accepted_credict_card");
     $paymentinfo->payment_discount_is_percent = $paymentparams->get('payment_discount_is_percent', '');
     $cartHelper = new rsCartHelper();
     $subtotal = $post['order_subtotal'];
     $update_discount = 0;
     if ($post['update_discount'] > 0) {
         $update_discount = $post['update_discount'];
         if ($update_discount > $subtotal) {
             $update_discount = $subtotal;
         }
         if ($update_discount != 0) {
             $order_total = $order_total - $update_discount;
         }
     }
     $special_discount = $post['special_discount'];
     $subtotal_excl_vat = 0;
     for ($i = 0; $i < count($orderItem); $i++) {
         $subtotal_excl_vat = $subtotal_excl_vat + $orderItem[$i]->prdexclprice * $orderItem[$i]->quantity;
     }
     if (APPLY_VAT_ON_DISCOUNT) {
         $amt = $subtotal;
     } else {
         $amt = $subtotal_excl_vat;
     }
     $discount_price = $amt * $special_discount / 100;
     $post['special_discount'] = $special_discount;
     $post['special_discount_amount'] = $discount_price;
     $order_total = $order_total - $discount_price;
     if (PAYMENT_CALCULATION_ON == 'subtotal') {
         $paymentAmount = $subtotal;
     } else {
         $paymentAmount = $order_total;
     }
     $paymentMethod = $cartHelper->calculatePayment($paymentAmount, $paymentinfo, $order_total);
     $post['ship_method_id'] = urldecode(urldecode($post['shipping_rate_id']));
     $order_total = $paymentMethod[0];
     $post['user_info_id'] = $post['users_info_id'];
     $post['payment_discount'] = $paymentMethod[1];
     $post['payment_oprand'] = $paymentinfo->payment_oprand;
     $post['order_discount'] = $update_discount;
     $post['order_total'] = $order_total;
     $post['order_payment_amount'] = $tmporder_total;
     $post['order_payment_name'] = $paymentmethod->name;
     if ($apply == 1) {
         $post['order_payment_status'] = 'Unpaid';
         $post['order_status'] = 'P';
     }
     if ($row = $model->store($post)) {
         $msg = JText::_('COM_REDSHOP_ORDER_DETAIL_SAVED');
     } else {
         $msg = JText::_('COM_REDSHOP_ERROR_SAVING_ORDER_DETAIL');
     }
     if ($apply == 1) {
         $objorder = new order_functions();
         $objorder->getpaymentinformation($row, $post);
     } else {
         $this->setRedirect('index.php?option=' . $option . '&view=order', $msg . $stocknote);
     }
 }
Пример #4
0
 public function updateItem($data)
 {
     $producthelper = new producthelper();
     $order_functions = new order_functions();
     $stockroomhelper = new rsstockroomhelper();
     $order_item_id = $data['order_item_id'];
     $orderitemdata = $this->getTable('order_item_detail');
     $orderitemdata->load($order_item_id);
     $orderdata = $this->getTable('order_detail');
     $orderdata->load($this->_id);
     $order_id = $this->_id;
     $product_id = $orderitemdata->product_id;
     $currentStock = $stockroomhelper->getStockroomTotalAmount($product_id);
     $user_id = $orderdata->user_id;
     $productPrice = $data['update_price'];
     $productPrice_new = 0;
     if ($productPrice < 0) {
         $productPrice_new = $productPrice;
         $productPrice = $productPrice * -1;
     }
     $customer_note = $data['customer_note'];
     $product_tax = $producthelper->getProductTax($product_id, $productPrice, $user_id);
     if ($productPrice_new < 0) {
         $product_tax = $product_tax * -1;
         $productPrice = $productPrice_new;
     }
     $new_added_qty = $data['quantity'] - $orderitemdata->product_quantity;
     if ($currentStock >= $new_added_qty || USE_STOCKROOM == 0) {
         $quantity = (int) $data['quantity'];
     } else {
         $quantity = (int) $orderitemdata->product_quantity;
     }
     $product_item_price = $productPrice + $product_tax;
     $product_item_price_excl_vat = $productPrice;
     $product_final_price = $product_item_price * $quantity;
     $productTotalTax = $product_tax * $quantity;
     $subtotal = $product_item_price * $quantity;
     $OrderItems = $order_functions->getOrderItemDetail($order_id);
     $totalTax = $product_tax * $quantity;
     for ($i = 0; $i < count($OrderItems); $i++) {
         if ($order_item_id != $OrderItems[$i]->order_item_id) {
             $itemtax = $OrderItems[$i]->product_item_price - $OrderItems[$i]->product_item_price_excl_vat;
             $totalTax = $totalTax + $itemtax * $OrderItems[$i]->product_quantity;
             $subtotal = $subtotal + $OrderItems[$i]->product_item_price * $OrderItems[$i]->product_quantity;
         }
         if ($order_item_id == $OrderItems[$i]->order_item_id) {
             $newquantity = $OrderItems[$i]->product_quantity - $quantity;
             if ($newquantity > 0) {
                 $stockroomhelper->manageStockAmount($product_id, $newquantity, $orderitemdata->stockroom_id);
             } elseif ($newquantity < 0) {
                 $updatestock = $stockroomhelper->updateStockroomQuantity($product_id, -$newquantity);
                 $stockroom_id_list = $updatestock['stockroom_list'];
                 $stockroom_quantity_list = $updatestock['stockroom_quantity_list'];
                 $orderitemdata->stockroom_id = $stockroom_id_list;
                 $orderitemdata->stockroom_quantity = $stockroom_quantity_list;
             }
             $this->updateAttributeItem($order_item_id, $newquantity, $orderitemdata->stockroom_id);
         }
     }
     $total = $subtotal + $orderdata->order_shipping - abs($orderdata->order_discount);
     $orderitemdata->product_item_price = $product_item_price;
     $orderitemdata->product_item_price_excl_vat = $product_item_price_excl_vat;
     $orderitemdata->product_final_price = $product_final_price;
     $orderitemdata->product_quantity = $quantity;
     $orderitemdata->customer_note = $customer_note;
     $orderdata->order_tax = $totalTax;
     $orderdata->order_total = $total;
     $orderdata->order_subtotal = $subtotal;
     if ($orderitemdata->store()) {
         if (!$orderdata->store()) {
             return false;
         }
         $tmpArr['special_discount'] = $orderdata->special_discount;
         $this->special_discount($tmpArr, true);
     } else {
         return false;
     }
     $order_functions->update_status();
     return true;
 }