User: pengcong Date: 2015/8/10 Time: 15:37
Exemplo n.º 1
0
 public function renderView()
 {
     if (!isset($_SESSION['cart'])) {
         $cart = new Cart();
         $_SESSION['cart'] = serialize($cart);
     }
     foreach ($this->model->getUris() as $key => $value) {
         if (preg_match("#^{$value}\$#", $this->uriView)) {
             if ($this->model->getView($key) === "PageView") {
                 $pagecontroller = new PageController($this->additionalParam);
                 $pagecontroller->renderView();
             } else {
                 if ($this->model->getView($key) === "ProductView") {
                     $productscontroller = new ProductsController();
                     $productscontroller->renderView();
                 } else {
                     if ($this->model->getView($key) === "SingleProductView") {
                         $singleproductcontroller = new SingleProductController($this->additionalParam);
                         $singleproductcontroller->renderView();
                     } else {
                         if ($this->model->getView($key) === "LoginView") {
                             $logincontroller = new LoginController($this->additionalParam);
                             $logincontroller->renderView();
                         } else {
                             if ($this->model->getView($key) === "CustomerView") {
                                 $customercontroller = new CustomerController();
                                 $customercontroller->renderView();
                             } else {
                                 if ($this->model->getView($key) === "CartView") {
                                     $cartcontroller = new CartController($this->additionalParam);
                                     $cartcontroller->renderView();
                                 } else {
                                     if ($this->model->getView($key) === "ContactView") {
                                         $contactcontroller = new ContactController($this->additionalParam);
                                         $contactcontroller->renderView();
                                     } else {
                                         if ($this->model->getView($key) === "RegisterView") {
                                             $registrationcontroller = new RegistrationController($this->additionalParam);
                                             $registrationcontroller->renderView();
                                         } else {
                                             if ($this->model->getView($key) === "CheckoutView") {
                                                 $checkoutcontroller = new CheckoutController($this->additionalParam);
                                                 $checkoutcontroller->renderView();
                                             } else {
                                                 $useView = $this->model->getView($key);
                                                 $view = new $useView();
                                                 $view->render();
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 public function admin_updateProductDetails()
 {
     $_REQUEST['avail_id'] = 2;
     $_REQUEST['start_date'] = "2012-10-31 00:00:00";
     $_REQUEST['end_date'] = "2014-04-16 14:15:07";
     $_REQUEST['estimated'] = "2014-04-16 14:15:07";
     return parent::admin_updateProductDetails();
 }
Exemplo n.º 3
0
 public function view($lookId)
 {
     $result = $this->Look->find("first", array("contain" => array("User", "LookItem" => array("Item" => array("fields" => array("sku", "name")), "LookArea"), "LookMedia", "Picture"), "conditions" => array("Look.id" => $lookId)));
     $look = array("id" => $result['Look']['id'], "status" => $result['Look']['look_status_id'], "name" => $result['Look']['name'], "notes" => $result['Look']['notes'], "likes" => $result['Look']['likes'], "creator" => array("id" => $result['User']['id'], "name" => $result['User']['first_name'] . " " . $result['User']['last_name'], "facebook_id" => $result['User']['facebook_id'], "img" => $result['User']['largeimage']), "items" => array(), "media" => array());
     foreach ($result['LookItem'] as $item) {
         if (!empty($item['Item']) && !empty($item['LookArea'])) {
             $lookAreaId = (int) $item['LookArea']['id'];
             if (empty($look['items'][$lookAreaId])) {
                 $look['items'][$lookAreaId] = array("name" => $item['LookArea']['name'], "producs" => array());
             }
             $Products = new ProductsController();
             //function to get current item SKU and Name
             $sku = $Products->getRedirectSku($item['Item']['sku']);
             //TODO: return items orderability
             //$enabled = ($Products->isProductAvailable($sku))? "enabled" : "disabled";
             $look['items'][$lookAreaId]['products'][] = array("sku" => $sku, "name" => $item['Item']['name'], "technique" => $item['technique'], "sub" => $item['sub']);
         }
     }
     $look['items'] = array_values($look['items']);
     foreach ($result['LookMedia'] as $media) {
         if ($media['type'] == Look::MEDIA_TYPE_PICTURE) {
             $picture = array("url" => S3LooksURL . $media['reference'] . ".jpg", "type" => Look::MEDIA_TYPE_PICTURE, 'thumb' => S3LooksURL . $media['reference'] . "_thumb.jpg");
             if ($media['id'] == $result['Look']['look_media_id']) {
                 $look['image'] = $picture;
             }
             $look['media'][] = $picture;
         } else {
             $look['media'][] = array("url" => "https://youtube.com/embed/" . $media['reference'], "type" => Look::MEDIA_TYPE_YOUTUBE, "thumb" => "https://img.youtube.com/vi/" . $media['reference'] . "/default.jpg");
         }
     }
     //Let's see if they specified a main image, if not just use the first image
     if (empty($look['image']) && !empty($look['media'])) {
         $look['image'] = $look['media'][0];
     }
     $look['items'] = array_values($look['items']);
     $this->sendSuccess($look);
 }
Exemplo n.º 4
0
 public function saveorderdetail()
 {
     $this->layout = 'index';
     $this->autoRender = false;
     $this->loadModel('OpenOrder');
     $this->loadModel('AssignService');
     $this->loadModel('Customer');
     $this->loadModel('OrderItem');
     $this->loadModel('Product');
     App::import('Vendor', 'linnwork/api/Auth');
     App::import('Vendor', 'linnwork/api/Factory');
     App::import('Vendor', 'linnwork/api/Orders');
     $username = Configure::read('linnwork_api_username');
     $password = Configure::read('linnwork_api_password');
     $multi = AuthMethods::Multilogin($username, $password);
     $auth = AuthMethods::Authorize($username, $password, $multi[0]->Id);
     $token = $auth->Token;
     $server = $auth->Server;
     $openorder = OrdersMethods::GetOpenOrders('100', '1', '', '', '00000000-0000-0000-0000-000000000000', '', $token, $server);
     foreach ($openorder->Data as $orderids) {
         $orders[] = $orderids->OrderId;
     }
     $results = OrdersMethods::GetOrders($orders, '00000000-0000-0000-0000-000000000000', true, true, $token, $server);
     $countryArray = array('Austria' => 'Austria', 'Belgium' => 'Belgium', 'Bulgaria' => 'Bulgaria', 'Croatia' => 'Croatia', 'Cyprus' => 'Cyprus', 'Czech Republic' => 'Czech Republic', 'Denmark' => 'Denmark', 'Estonia' => 'Estonia', 'Finland' => 'Finland', 'France' => 'France', 'Germany' => 'Germany', 'Greece' => 'Greece', 'Hungary' => 'Hungary', 'Ireland' => 'Ireland', 'Italy' => 'Italy', 'Latvia' => 'Latvia', 'Lithuania' => 'Lithuania', 'Luxembourg' => 'Luxembourg', 'Malta' => 'Malta', 'Netherlands' => 'Netherlands', 'Poland' => 'Poland', 'Portugal' => 'Portugal', 'Romania' => 'Romania', 'Slovakia' => 'Slovakia', 'Slovenia' => 'Slovenia', 'Spain' => 'Spain', 'Sweden' => 'Sweden', 'United Kingdom' => 'United Kingdom');
     foreach ($results as $result) {
         if (($result->GeneralInfo->Status == 1 || $result->GeneralInfo->Status == 4) && $result->GeneralInfo->HoldOrCancel == '') {
             $data['order_id'] = $result->OrderId;
             $data['num_order_id'] = $result->NumOrderId;
             $data['general_info'] = serialize($result->GeneralInfo);
             $data['shipping_info'] = serialize($result->ShippingInfo);
             $data['customer_info'] = serialize($result->CustomerInfo);
             $data['totals_info'] = serialize($result->TotalsInfo);
             $data['folder_name'] = serialize($result->FolderName);
             $data['items'] = serialize($result->Items);
             //Extra information will save my according to manage sorting station section
             $country = $data['destination'] = $result->CustomerInfo->Address->Country;
             $orderitems = unserialize($data['items']);
             $this->OpenOrder->create();
             $checkorder = $this->OpenOrder->find('all', array('conditions' => array('OpenOrder.order_id' => $result->OrderId)));
             if (count($checkorder) > 0) {
             } else {
                 $this->OpenOrder->save($data);
                 //pr($result); exit;
                 $getCurrencyText = $result->TotalsInfo->Currency;
                 if ($getCurrencyText == "EUR") {
                     $baseRate = '1';
                 } else {
                     $baseRate = '1.38';
                 }
                 //pr($orderitems);
                 /***************** split the order item ******************/
                 $bundleIdentity = 0;
                 foreach ($orderitems as $orderitem) {
                     echo $orderitem->SKU . '==' . $orderitem->PricePerUnit;
                     echo "<br>";
                     $splitskus = explode('-', $orderitem->SKU);
                     $count = count($splitskus);
                     if (count($orderitems) > 1) {
                         $orderGroup = "Group B";
                     } else {
                         $orderGroup = "Group A";
                     }
                     //Find Country
                     if (in_array($country, $countryArray)) {
                         //It means, Inside EU country shipping for bundle with sameSKU
                         if ($splitskus['0'] == 'B') {
                             for ($i = 1; $i <= count($splitskus) - 2; $i++) {
                                 if ($count == 3) {
                                     echo $value = $orderitem->Quantity * $orderitem->PricePerUnit * $baseRate;
                                     //echo $value = $orderitem->CostIncTax * $baseRate;
                                     echo "<br>";
                                     //For Euro
                                     if ($value <= 35 || $value > 150) {
                                         $numId = '';
                                         if ($bundleIdentity > 0) {
                                             $bundleIdentity = $bundleIdentity + 1;
                                             $numId = $result->NumOrderId . '-' . $bundleIdentity;
                                             $splititem['product_order_id_identify'] = $numId;
                                             $splititem['order_split'] = $orderGroup;
                                             //$splititem['order_split']		=	"split";
                                         } else {
                                             if (count($orderitems) == 1) {
                                                 $numId = $result->NumOrderId;
                                             } else {
                                                 $bundleIdentity = $bundleIdentity + 1;
                                                 $numId = $result->NumOrderId . '-' . $bundleIdentity;
                                                 $splititem['product_order_id_identify'] = $numId;
                                                 $splititem['order_split'] = $orderGroup;
                                                 //$splititem['order_split']		=	"split";
                                             }
                                         }
                                         $splititem['order_split'] = $orderGroup;
                                         $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                         $splititem['product_sku_identifier'] = "single";
                                         $splititem['price'] = $orderitem->PricePerUnit;
                                         $splititem['quantity'] = $orderitem->Quantity;
                                         $splititem['product_type'] = "bundle";
                                         $splititem['order_id'] = $result->NumOrderId;
                                         $splititem['sku'] = 'S-' . $splitskus[$i];
                                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                         $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                         $this->OrderItem->create();
                                         $this->OrderItem->save($splititem);
                                     } else {
                                         if ($value <= 150 && $value > 35) {
                                             $total = 0;
                                             $perUnitPrice = $orderitem->Quantity * $orderitem->PricePerUnit;
                                             $orderQuantity = $orderitem->Quantity * $splitskus[$count - 1];
                                             $itemPrice = $perUnitPrice / $orderQuantity;
                                             $inc = 0;
                                             $checkOuter = 0;
                                             $isLeader = false;
                                             if ($orderQuantity > 1) {
                                                 //It will be the same as Linnworks custom script term , So now will split the orders with SEQUENCING
                                                 $e = 0;
                                                 while ($e <= $orderQuantity - 1) {
                                                     //$total = $total + ( $baseRate * $itemPrice );
                                                     if ($total + $baseRate * $itemPrice <= 35) {
                                                         $total = $total + $baseRate * $itemPrice;
                                                         echo $total;
                                                         echo "<br>";
                                                         $inc++;
                                                         $checkOuter++;
                                                         $isLeader = true;
                                                         if ($e == $orderQuantity - 1) {
                                                             echo "Now Split" . $total;
                                                             echo "<br>*********<br>";
                                                             //Splitting the order accordign the rule
                                                             //Store previous then initialized
                                                             $bundleIdentity++;
                                                             //Store and split the same SKU bundle order
                                                             $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                             $splititem['product_sku_identifier'] = "single";
                                                             $splititem['price'] = $total / $baseRate;
                                                             $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                             $splititem['order_split'] = $orderGroup;
                                                             $splititem['quantity'] = $inc;
                                                             $splititem['product_type'] = "bundle";
                                                             $splititem['order_id'] = $result->NumOrderId;
                                                             $splititem['sku'] = 'S-' . $splitskus[$i];
                                                             $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                             $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                             pr($splititem);
                                                             $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                             $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                             $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                             $this->OrderItem->create();
                                                             $this->OrderItem->save($splititem);
                                                             $total = 0;
                                                             $inc = 1;
                                                             $total = $total + $baseRate * $itemPrice;
                                                             echo $total;
                                                             echo "<br>";
                                                         }
                                                     } else {
                                                         if ($isLeader == false) {
                                                             //Increase Counter
                                                             $checkOuter++;
                                                             $total = $total + $baseRate * $itemPrice;
                                                             if ($e == $orderQuantity - 1) {
                                                                 $inc = 1;
                                                                 echo "Now Split " . $total;
                                                                 echo "<br>";
                                                                 //Splitting the order accordign the rule
                                                                 //Store previous then initialized
                                                                 $bundleIdentity++;
                                                                 //Store and split the same SKU bundle order
                                                                 $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                                 $splititem['product_sku_identifier'] = "single";
                                                                 $splititem['price'] = $total / $baseRate;
                                                                 $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                                 $splititem['order_split'] = $orderGroup;
                                                                 //$splititem['order_split']		=	"split";
                                                                 $splititem['quantity'] = $checkOuter;
                                                                 $splititem['product_type'] = "bundle";
                                                                 $splititem['order_id'] = $result->NumOrderId;
                                                                 $splititem['sku'] = 'S-' . $splitskus[$i];
                                                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                                 pr($splititem);
                                                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                                 $this->OrderItem->create();
                                                                 $this->OrderItem->save($splititem);
                                                                 $total = 0;
                                                                 $inc = 0;
                                                             }
                                                         } else {
                                                             if ($e == $orderQuantity - 1) {
                                                                 //For Previous calculate and store it split order into database
                                                                 echo "Now Split------" . $total;
                                                                 echo "<br>*********<br>";
                                                                 //Splitting the order accordign the rule
                                                                 //Store previous then initialized
                                                                 $bundleIdentity++;
                                                                 //Store and split the same SKU bundle order
                                                                 $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                                 $splititem['product_sku_identifier'] = "single";
                                                                 $splititem['price'] = $total / $baseRate;
                                                                 $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                                 //$splititem['order_split']		=	"split";
                                                                 $splititem['order_split'] = $orderGroup;
                                                                 $splititem['quantity'] = $inc;
                                                                 $splititem['product_type'] = "bundle";
                                                                 $splititem['order_id'] = $result->NumOrderId;
                                                                 $splititem['sku'] = 'S-' . $splitskus[$i];
                                                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                                 pr($splititem);
                                                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                                 $this->OrderItem->create();
                                                                 $this->OrderItem->save($splititem);
                                                                 $total = 0;
                                                                 $inc = 1;
                                                                 $total = $total + $baseRate * $itemPrice;
                                                                 echo $total;
                                                                 echo "<br>";
                                                                 //Now store last index calculation if reaches at end point then
                                                                 //need to be remind , there is last one we have to also store into database
                                                                 echo "Now Split" . $total;
                                                                 echo "<br>*********<br>";
                                                                 //Splitting the order accordign the rule
                                                                 //Store previous then initialized
                                                                 $bundleIdentity++;
                                                                 //Store and split the same SKU bundle order
                                                                 $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                                 $splititem['product_sku_identifier'] = "single";
                                                                 $splititem['price'] = $total / $baseRate;
                                                                 $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                                 //$splititem['order_split']		=	"split";
                                                                 $splititem['order_split'] = $orderGroup;
                                                                 $splititem['quantity'] = $inc;
                                                                 $splititem['product_type'] = "bundle";
                                                                 $splititem['order_id'] = $result->NumOrderId;
                                                                 $splititem['sku'] = 'S-' . $splitskus[$i];
                                                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                                 pr($splititem);
                                                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                                 $this->OrderItem->create();
                                                                 $this->OrderItem->save($splititem);
                                                                 $total = 0;
                                                                 $inc = 1;
                                                                 $total = $total + $baseRate * $itemPrice;
                                                                 echo $total;
                                                                 echo "<br>";
                                                             } else {
                                                                 echo "Now Split " . $total;
                                                                 echo "<br>";
                                                                 //Splitting the order accordign the rule
                                                                 //Store previous then initialized
                                                                 $bundleIdentity++;
                                                                 //Store and split the same SKU bundle order
                                                                 $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                                 $splititem['product_sku_identifier'] = "single";
                                                                 $splititem['price'] = $total / $baseRate;
                                                                 $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                                 //$splititem['order_split']		=	"split";
                                                                 $splititem['order_split'] = $orderGroup;
                                                                 $splititem['quantity'] = $inc;
                                                                 $splititem['product_type'] = "bundle";
                                                                 $splititem['order_id'] = $result->NumOrderId;
                                                                 $splititem['sku'] = 'S-' . $splitskus[$i];
                                                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                                 pr($splititem);
                                                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                                 $this->OrderItem->create();
                                                                 $this->OrderItem->save($splititem);
                                                                 $total = 0;
                                                                 $inc = 1;
                                                                 $total = $total + $baseRate * $itemPrice;
                                                                 echo $total;
                                                                 echo "<br>";
                                                             }
                                                         }
                                                     }
                                                     $e++;
                                                 }
                                             }
                                         } else {
                                             //echo "Exceed Limit to split."; exit;
                                         }
                                     }
                                 } else {
                                     //Get Count Sku for bundle with multiple
                                     $getLastIndex = $splitskus[count($splitskus) - 1];
                                     //Handle Multiple Sku with type bundle
                                     echo $value = $orderitem->Quantity * ($orderitem->PricePerUnit / $getLastIndex) * $baseRate;
                                     //echo $value = $orderitem->CostIncTax * $baseRate;
                                     echo "<br>";
                                     $anotherValue = $orderitem->Quantity * $orderitem->PricePerUnit * $baseRate;
                                     //For Euro
                                     if ($anotherValue <= 35 || $anotherValue > 150) {
                                         //Check bundle with single Sku if comes under 35 from single SKU
                                         /*$numId = '';
                                         		if( $bundleIdentity > 0 )
                                         		{
                                         			$bundleIdentity = $bundleIdentity + 1;												
                                         			$numId = $result->NumOrderId .'-'. $bundleIdentity;
                                         			$splititem['product_order_id_identify']		=	$numId;
                                         			$splititem['order_split']		=	$orderGroup;
                                         		}
                                         		else
                                         		{
                                         			$bundleIdentity = $bundleIdentity + 1;	
                                         			$numId = $result->NumOrderId .'-'. $bundleIdentity;	
                                         			$splititem['product_order_id_identify']		=	$numId;
                                         			$splititem['order_split']		=	$orderGroup;														
                                         		}
                                         		
                                         		$splititem['order_split']		=	$orderGroup;
                                         		$splititem['pack_order_quantity']		=	$splitskus[$count-1];
                                         		$splititem['product_sku_identifier']		= "multiple";			
                                         		$splititem['price']		=	$value; //$orderitem->PricePerUnit;
                                         		
                                         		$splititem['quantity']			=	$orderitem->Quantity;
                                         		$splititem['product_type']		=	"bundle";
                                         		$splititem['order_id']		=	$result->NumOrderId;
                                         		$splititem['sku']			=	'S-'.$splitskus[$i];
                                         		$productDetail				=	$this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'] )));
                                         		$splititem['barcode']		=	$productDetail['ProductDesc']['barcode'];
                                         		
                                         		$productDetail['Product']['current_stock_level']	= $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                         		$productDetail['Product']['lock_qty']				= $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                         		
                                         		$this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']),
                                         									array('Product.product_sku' => $splititem['sku']));
                                         		$this->OrderItem->create();
                                         		$this->OrderItem->save( $splititem );*/
                                         if (count($splitskus) - 2 == $i) {
                                             echo $totalQuantity = $orderitem->Quantity * $getLastIndex;
                                             echo "<br>";
                                             $combinedSkuForMulti .= ',' . $orderitem->Quantity . 'X' . 'S-' . $splitskus[$i];
                                             if ($bundleIdentity > 0) {
                                                 if (count($orderitems) > 1) {
                                                     $bundleIdentity = $bundleIdentity + 1;
                                                     $numId = $result->NumOrderId . '-' . $bundleIdentity;
                                                 } else {
                                                     $numId = $result->NumOrderId;
                                                 }
                                             } else {
                                                 if (count($orderitems) > 1) {
                                                     $bundleIdentity = $bundleIdentity + 1;
                                                     $numId = $result->NumOrderId . '-' . $bundleIdentity;
                                                 } else {
                                                     $numId = $result->NumOrderId;
                                                 }
                                             }
                                             $splititem['product_order_id_identify'] = $numId;
                                             $splititem['order_split'] = "Group B";
                                             $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                             $splititem['product_sku_identifier'] = "multiple";
                                             $splititem['price'] = $orderitem->PricePerUnit;
                                             $splititem['quantity'] = $totalQuantity;
                                             $splititem['product_type'] = "bundle";
                                             $splititem['order_id'] = $result->NumOrderId;
                                             $splititem['sku'] = $combinedSkuForMulti;
                                             $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                             $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                             $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                             $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                             $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                             $this->OrderItem->create();
                                             $this->OrderItem->save($splititem);
                                         } else {
                                             echo $totalQuantity = $orderitem->Quantity * $getLastIndex;
                                             echo "<br>";
                                             if ($i == 1) {
                                                 $combinedSkuForMulti = $orderitem->Quantity . 'X' . 'S-' . $splitskus[$i];
                                             } else {
                                                 $combinedSkuForMulti .= ',' . $orderitem->Quantity . 'X' . 'S-' . $splitskus[$i];
                                             }
                                         }
                                     } else {
                                         if ($anotherValue <= 150 && $anotherValue > 35) {
                                             $total = 0;
                                             $perUnitPrice = $orderitem->Quantity * ($orderitem->PricePerUnit / $getLastIndex);
                                             $orderQuantity = $orderitem->Quantity;
                                             $itemPrice = $perUnitPrice / $orderQuantity;
                                             $inc = 0;
                                             $checkOuter = 0;
                                             $isLeader = false;
                                             if ($orderQuantity > 0) {
                                                 //It will be the same as Linnworks custom script term , So now will split the orders with SEQUENCING
                                                 $e = 0;
                                                 while ($e <= $orderQuantity - 1) {
                                                     //$total = $total + ( $baseRate * $itemPrice );
                                                     if ($total + $baseRate * $itemPrice <= 35) {
                                                         $total = $total + $baseRate * $itemPrice;
                                                         echo $total;
                                                         echo "<br>";
                                                         $inc++;
                                                         $checkOuter++;
                                                         $isLeader = true;
                                                         if ($e == $orderQuantity - 1) {
                                                             echo "Now Split" . $total;
                                                             echo "<br>*********<br>";
                                                             //Splitting the order accordign the rule
                                                             //Store previous then initialized
                                                             $bundleIdentity++;
                                                             //Store and split the same SKU bundle order
                                                             $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                             $splititem['product_sku_identifier'] = "multiple";
                                                             $splititem['price'] = $total / $baseRate;
                                                             $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                             $splititem['order_split'] = "Group B";
                                                             //$orderGroup;
                                                             $splititem['quantity'] = $inc;
                                                             $splititem['product_type'] = "bundle";
                                                             $splititem['order_id'] = $result->NumOrderId;
                                                             $splititem['sku'] = 'S-' . $splitskus[$i];
                                                             $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                             $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                             pr($splititem);
                                                             $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                             $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                             $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                             $this->OrderItem->create();
                                                             $this->OrderItem->save($splititem);
                                                             $total = 0;
                                                             $inc = 1;
                                                             $total = $total + $baseRate * $itemPrice;
                                                             echo $total;
                                                             echo "<br>";
                                                         }
                                                     } else {
                                                         if ($isLeader == false) {
                                                             //Increase Counter
                                                             $checkOuter++;
                                                             $total = $total + $baseRate * $itemPrice;
                                                             if ($e == $orderQuantity - 1) {
                                                                 $inc = 1;
                                                                 echo "Now Split " . $total;
                                                                 echo "<br>";
                                                                 //Splitting the order accordign the rule
                                                                 //Store previous then initialized
                                                                 $bundleIdentity++;
                                                                 //Store and split the same SKU bundle order
                                                                 $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                                 $splititem['product_sku_identifier'] = "multiple";
                                                                 $splititem['price'] = $total / $baseRate;
                                                                 $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                                 $splititem['order_split'] = "Group B";
                                                                 //$orderGroup;
                                                                 //$splititem['order_split']		=	"split";
                                                                 $splititem['quantity'] = $checkOuter;
                                                                 $splititem['product_type'] = "bundle";
                                                                 $splititem['order_id'] = $result->NumOrderId;
                                                                 $splititem['sku'] = 'S-' . $splitskus[$i];
                                                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                                 pr($splititem);
                                                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                                 $this->OrderItem->create();
                                                                 $this->OrderItem->save($splititem);
                                                                 $total = 0;
                                                                 $inc = 0;
                                                             }
                                                         } else {
                                                             if ($e == $orderQuantity - 1) {
                                                                 //For Previous calculate and store it split order into database
                                                                 echo "Now Split------" . $total;
                                                                 echo "<br>*********<br>";
                                                                 //Splitting the order accordign the rule
                                                                 //Store previous then initialized
                                                                 $bundleIdentity++;
                                                                 //Store and split the same SKU bundle order
                                                                 $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                                 $splititem['product_sku_identifier'] = "multiple";
                                                                 $splititem['price'] = $total / $baseRate;
                                                                 $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                                 //$splititem['order_split']		=	"split";
                                                                 $splititem['order_split'] = "Group B";
                                                                 //$orderGroup;
                                                                 $splititem['quantity'] = $inc;
                                                                 $splititem['product_type'] = "bundle";
                                                                 $splititem['order_id'] = $result->NumOrderId;
                                                                 $splititem['sku'] = 'S-' . $splitskus[$i];
                                                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                                 pr($splititem);
                                                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                                 $this->OrderItem->create();
                                                                 $this->OrderItem->save($splititem);
                                                                 $total = 0;
                                                                 $inc = 1;
                                                                 $total = $total + $baseRate * $itemPrice;
                                                                 echo $total;
                                                                 echo "<br>";
                                                                 //Now store last index calculation if reaches at end point then
                                                                 //need to be remind , there is last one we have to also store into database
                                                                 echo "Now Split" . $total;
                                                                 echo "<br>*********<br>";
                                                                 //Splitting the order accordign the rule
                                                                 //Store previous then initialized
                                                                 $bundleIdentity++;
                                                                 //Store and split the same SKU bundle order
                                                                 $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                                 $splititem['product_sku_identifier'] = "multiple";
                                                                 $splititem['price'] = $total / $baseRate;
                                                                 $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                                 //$splititem['order_split']		=	"split";
                                                                 $splititem['order_split'] = "Group B";
                                                                 //$orderGroup;
                                                                 $splititem['quantity'] = $inc;
                                                                 $splititem['product_type'] = "bundle";
                                                                 $splititem['order_id'] = $result->NumOrderId;
                                                                 $splititem['sku'] = 'S-' . $splitskus[$i];
                                                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                                 pr($splititem);
                                                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                                 $this->OrderItem->create();
                                                                 $this->OrderItem->save($splititem);
                                                                 $total = 0;
                                                                 $inc = 1;
                                                                 $total = $total + $baseRate * $itemPrice;
                                                                 echo $total;
                                                                 echo "<br>";
                                                             } else {
                                                                 echo "Now Split " . $total;
                                                                 echo "<br>";
                                                                 //Splitting the order accordign the rule
                                                                 //Store previous then initialized
                                                                 $bundleIdentity++;
                                                                 //Store and split the same SKU bundle order
                                                                 $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                                 $splititem['product_sku_identifier'] = "multiple";
                                                                 $splititem['price'] = $total / $baseRate;
                                                                 $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                                 //$splititem['order_split']		=	"split";
                                                                 $splititem['order_split'] = "Group B";
                                                                 //$orderGroup;
                                                                 $splititem['quantity'] = $inc;
                                                                 $splititem['product_type'] = "bundle";
                                                                 $splititem['order_id'] = $result->NumOrderId;
                                                                 $splititem['sku'] = 'S-' . $splitskus[$i];
                                                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                                 pr($splititem);
                                                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                                 $this->OrderItem->create();
                                                                 $this->OrderItem->save($splititem);
                                                                 $total = 0;
                                                                 $inc = 1;
                                                                 $total = $total + $baseRate * $itemPrice;
                                                                 echo $total;
                                                                 echo "<br>";
                                                             }
                                                         }
                                                     }
                                                     $e++;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         } else {
                             // Single SKU order splitting
                             echo $value = $orderitem->Quantity * $orderitem->PricePerUnit * $baseRate;
                             //echo $value = $orderitem->CostIncTax * $baseRate;
                             echo "<br>";
                             //For Euro
                             if ($value <= 35 || $value > 150) {
                                 $numId = '';
                                 if ($bundleIdentity > 0) {
                                     $bundleIdentity = $bundleIdentity + 1;
                                     $numId = $result->NumOrderId . '-' . $bundleIdentity;
                                     $splititem['product_order_id_identify'] = $numId;
                                     //$splititem['order_split']		=	"split";
                                 } else {
                                     if (count($orderitems) == 1) {
                                         $numId = $result->NumOrderId;
                                     } else {
                                         $bundleIdentity = $bundleIdentity + 1;
                                         $numId = $result->NumOrderId . '-' . $bundleIdentity;
                                         $splititem['product_order_id_identify'] = $numId;
                                         //$splititem['order_split']		=	"split";
                                     }
                                 }
                                 $splititem['order_split'] = $orderGroup;
                                 $splititem['pack_order_quantity'] = 0;
                                 $splititem['product_sku_identifier'] = "single";
                                 $splititem['price'] = $orderitem->PricePerUnit;
                                 $splititem['quantity'] = $orderitem->Quantity;
                                 $splititem['product_type'] = "single";
                                 $splititem['order_id'] = $result->NumOrderId;
                                 $splititem['sku'] = $orderitem->SKU;
                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                 $this->OrderItem->create();
                                 $this->OrderItem->save($splititem);
                             } else {
                                 if ($value <= 150 && $value > 35) {
                                     $total = 0;
                                     $perUnitPrice = $orderitem->Quantity * $orderitem->PricePerUnit;
                                     $orderQuantity = $orderitem->Quantity;
                                     $itemPrice = $perUnitPrice / $orderQuantity;
                                     $inc = 0;
                                     $checkOuter = 0;
                                     $isLeader = false;
                                     if ($orderQuantity > 1) {
                                         //It will be the same as Linnworks custom script term , So now will split the orders with SEQUENCING
                                         $e = 0;
                                         while ($e <= $orderQuantity - 1) {
                                             //$total = $total + ( $baseRate * $itemPrice );
                                             if ($total + $baseRate * $itemPrice <= 35) {
                                                 $total = $total + $baseRate * $itemPrice;
                                                 echo $total;
                                                 echo "<br>";
                                                 $inc++;
                                                 $checkOuter++;
                                                 $isLeader = true;
                                                 if ($e == $orderQuantity - 1) {
                                                     echo "Now Split" . $total;
                                                     echo "<br>*********<br>";
                                                     //Splitting the order accordign the rule
                                                     //Store previous then initialized
                                                     $bundleIdentity++;
                                                     //Store and split the same SKU bundle order
                                                     $splititem['pack_order_quantity'] = 0;
                                                     $splititem['product_sku_identifier'] = "single";
                                                     $splititem['price'] = $total / $baseRate;
                                                     $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                     //$splititem['order_split']		=	"split";
                                                     $splititem['order_split'] = $orderGroup;
                                                     $splititem['quantity'] = $inc;
                                                     $splititem['product_type'] = "single";
                                                     $splititem['order_id'] = $result->NumOrderId;
                                                     $splititem['sku'] = $orderitem->SKU;
                                                     $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                     $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                     pr($splititem);
                                                     $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                     $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                     $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                     $this->OrderItem->create();
                                                     $this->OrderItem->save($splititem);
                                                     $total = 0;
                                                     $inc = 1;
                                                     $total = $total + $baseRate * $itemPrice;
                                                     echo $total;
                                                     echo "<br>";
                                                 }
                                             } else {
                                                 if ($isLeader == false) {
                                                     //Increase Counter
                                                     $checkOuter++;
                                                     $total = $total + $baseRate * $itemPrice;
                                                     if ($e == $orderQuantity - 1) {
                                                         $inc = 1;
                                                         echo "Now Split " . $total;
                                                         echo "<br>";
                                                         //Splitting the order accordign the rule
                                                         //Store previous then initialized
                                                         $bundleIdentity++;
                                                         //Store and split the same SKU bundle order
                                                         $splititem['pack_order_quantity'] = 0;
                                                         $splititem['product_sku_identifier'] = "single";
                                                         $splititem['price'] = $total / $baseRate;
                                                         $splititem['product_order_id_identify'] = $result->NumOrderId;
                                                         $splititem['order_split'] = $orderGroup;
                                                         $splititem['quantity'] = $checkOuter;
                                                         $splititem['product_type'] = "single";
                                                         $splititem['order_id'] = $result->NumOrderId;
                                                         $splititem['sku'] = $orderitem->SKU;
                                                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                         $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                         pr($splititem);
                                                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                         $this->OrderItem->create();
                                                         $this->OrderItem->save($splititem);
                                                         $total = 0;
                                                         $inc = 0;
                                                     }
                                                 } else {
                                                     if ($e == $orderQuantity - 1) {
                                                         //For Previous calculate and store it split order into database
                                                         echo "Now Split------" . $total;
                                                         echo "<br>*********<br>";
                                                         //Splitting the order accordign the rule
                                                         //Store previous then initialized
                                                         $bundleIdentity++;
                                                         //Store and split the same SKU bundle order
                                                         $splititem['pack_order_quantity'] = 0;
                                                         $splititem['product_sku_identifier'] = "single";
                                                         $splititem['price'] = $total / $baseRate;
                                                         $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                         //$splititem['order_split']		=	"split";
                                                         $splititem['order_split'] = $orderGroup;
                                                         $splititem['quantity'] = $inc;
                                                         $splititem['product_type'] = "single";
                                                         $splititem['order_id'] = $result->NumOrderId;
                                                         $splititem['sku'] = $orderitem->SKU;
                                                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                         $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                         pr($splititem);
                                                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                         $this->OrderItem->create();
                                                         $this->OrderItem->save($splititem);
                                                         $total = 0;
                                                         $inc = 1;
                                                         $total = $total + $baseRate * $itemPrice;
                                                         echo $total;
                                                         echo "<br>";
                                                         //Now store last index calculation if reaches at end point then
                                                         //need to be remind , there is last one we have to also store into database
                                                         echo "Now Split" . $total;
                                                         echo "<br>*********<br>";
                                                         //Splitting the order accordign the rule
                                                         //Store previous then initialized
                                                         $bundleIdentity++;
                                                         //Store and split the same SKU bundle order
                                                         $splititem['pack_order_quantity'] = 0;
                                                         $splititem['product_sku_identifier'] = "single";
                                                         $splititem['price'] = $total / $baseRate;
                                                         $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                         $splititem['order_split'] = $orderGroup;
                                                         $splititem['quantity'] = $inc;
                                                         $splititem['product_type'] = "single";
                                                         $splititem['order_id'] = $result->NumOrderId;
                                                         $splititem['sku'] = $orderitem->SKU;
                                                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                         $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                         pr($splititem);
                                                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                         $this->OrderItem->create();
                                                         $this->OrderItem->save($splititem);
                                                         $total = 0;
                                                         $inc = 1;
                                                         $total = $total + $baseRate * $itemPrice;
                                                         echo $total;
                                                         echo "<br>";
                                                     } else {
                                                         echo "Now Split " . $total;
                                                         echo "<br>";
                                                         //Splitting the order accordign the rule
                                                         //Store previous then initialized
                                                         $bundleIdentity++;
                                                         //Store and split the same SKU bundle order
                                                         $splititem['pack_order_quantity'] = 0;
                                                         $splititem['product_sku_identifier'] = "single";
                                                         $splititem['price'] = $total / $baseRate;
                                                         $splititem['product_order_id_identify'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                         $splititem['order_split'] = $orderGroup;
                                                         $splititem['quantity'] = $inc;
                                                         $splititem['product_type'] = "single";
                                                         $splititem['order_id'] = $result->NumOrderId;
                                                         $splititem['sku'] = $orderitem->SKU;
                                                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                         $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                         pr($splititem);
                                                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                         $this->OrderItem->create();
                                                         $this->OrderItem->save($splititem);
                                                         $total = 0;
                                                         $inc = 1;
                                                         $total = $total + $baseRate * $itemPrice;
                                                         echo $total;
                                                         echo "<br>";
                                                     }
                                                 }
                                             }
                                             $e++;
                                         }
                                     } else {
                                         //If order item count is 1 then would be store directly
                                         $splititem['pack_order_quantity'] = 0;
                                         $splititem['product_sku_identifier'] = "single";
                                         $splititem['price'] = $orderitem->PricePerUnit;
                                         $splititem['order_split'] = $orderGroup;
                                         $splititem['quantity'] = $orderitem->Quantity;
                                         $splititem['product_type'] = "single";
                                         $splititem['order_id'] = $result->NumOrderId;
                                         $splititem['sku'] = $orderitem->SKU;
                                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                         $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                         $this->OrderItem->create();
                                         $this->OrderItem->save($splititem);
                                     }
                                 } else {
                                     //echo "Exceed Limit to split."; exit;
                                 }
                             }
                         }
                     } else {
                         //It means, Outside EU country shipping
                         //pr($orderitem);
                         if (count(explode('-', $orderitem->SKU)) == 2) {
                             // For Single Type Sku
                             //If order item count is 1 then would be store directly
                             $splititem['pack_order_quantity'] = 0;
                             $splititem['product_sku_identifier'] = "single";
                             $splititem['price'] = $orderitem->PricePerUnit;
                             $splititem['order_split'] = $orderGroup;
                             $splititem['quantity'] = $orderitem->Quantity;
                             $splititem['product_type'] = "single";
                             $splititem['order_id'] = $result->NumOrderId;
                             $splititem['sku'] = $orderitem->SKU;
                             $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                             $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                             $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                             $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                             $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                             $this->OrderItem->create();
                             $this->OrderItem->save($splititem);
                         } else {
                             if (count(explode('-', $orderitem->SKU)) == 3) {
                                 $splitskus = explode('-', $orderitem->SKU);
                                 // For Bundle with same type Sku
                                 //Store and split the same SKU bundle order
                                 $splititem['pack_order_quantity'] = $splitskus[2];
                                 $splititem['product_sku_identifier'] = "single";
                                 $splititem['price'] = $orderitem->Quantity * $orderitem->PricePerUnit;
                                 $splititem['product_order_id_identify'] = $result->NumOrderId;
                                 $splititem['order_split'] = $orderGroup;
                                 $splititem['quantity'] = $orderitem->Quantity;
                                 $splititem['product_type'] = "bundle";
                                 $splititem['order_id'] = $result->NumOrderId;
                                 $splititem['sku'] = 'S-' . $splitskus[1];
                                 $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                 $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                 pr($splititem);
                                 $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                 $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                 $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                 $this->OrderItem->create();
                                 $this->OrderItem->save($splititem);
                             }
                         }
                         if (count(explode('-', $orderitem->SKU)) > 3) {
                             // For Bundle with muti type Sku
                         } else {
                         }
                     }
                 }
                 //************** Merge Order after splitting with different scenarios **************
                 $this->mergeSplitOrdersByOrderId_AccordingRules($result->NumOrderId);
                 //$this->loadModel( 'MergeOrder' );
                 //pr( $this->MergeOrder->find('all') ); exit;
                 // code for save customer detail
                 $customerInfo['Customer']['email'] = $result->CustomerInfo->Address->EmailAddress;
                 $customerInfo['Customer']['address1'] = $result->CustomerInfo->Address->Address1;
                 $customerInfo['Customer']['address2'] = $result->CustomerInfo->Address->Address2;
                 $customerInfo['Customer']['address3'] = $result->CustomerInfo->Address->Address3;
                 $customerInfo['Customer']['town'] = $result->CustomerInfo->Address->Town;
                 $customerInfo['Customer']['region'] = $result->CustomerInfo->Address->Region;
                 $customerInfo['Customer']['postcode'] = $result->CustomerInfo->Address->PostCode;
                 $customerInfo['Customer']['country'] = $result->CustomerInfo->Address->Country;
                 $customerInfo['Customer']['name'] = $result->CustomerInfo->Address->FullName;
                 $customerInfo['Customer']['company'] = $result->CustomerInfo->Address->Company;
                 $customerInfo['Customer']['phone'] = $result->CustomerInfo->Address->PhoneNumber;
                 $customerInfo['Customer']['source'] = $result->GeneralInfo->Source;
                 $customerInfo['Customer']['subsource'] = $result->GeneralInfo->SubSource;
                 $customerdetails = $this->Customer->find('first', array('conditions' => array('Customer.email' => $customerInfo['Customer']['email'])));
                 if (count($customerdetails) > 0) {
                     //$customerdetails['Customer']['count'] = $customerdetails['Customer']['count'] + '1';
                     $this->Customer->updateAll(array('Customer.order_id' => $result->NumOrderId), array('Customer.email' => $customerdetails['Customer']['email']));
                 } else {
                     $customerInfo['Customer']['order_id'] = $result->NumOrderId;
                     $this->Customer->create();
                     $this->Customer->saveAll($customerInfo);
                 }
             }
         } else {
             //Do something you required
         }
     }
     /* call the function for assign the postal servises */
     $this->assign_services();
     $this->getBarcode();
     $this->setAgainAssignedServiceToAllOrder();
     // Euraco Group
     App::import('Controller', 'Products');
     $productModel = new ProductsController();
     $productModel->prepareVirtualStock();
 }
 public function prepareExcel()
 {
     $this->layout = '';
     $this->autoRender = false;
     echo ProductsController::productStockExcel();
     exit;
 }
Exemplo n.º 6
0
 public function saveorderdetail()
 {
     $this->layout = 'index';
     $this->autoRender = false;
     $this->loadModel('OpenOrder');
     $this->loadModel('AssignService');
     $this->loadModel('Customer');
     $this->loadModel('OrderItem');
     $this->loadModel('Product');
     App::import('Vendor', 'linnwork/api/Auth');
     App::import('Vendor', 'linnwork/api/Factory');
     App::import('Vendor', 'linnwork/api/Orders');
     $username = Configure::read('linnwork_api_username');
     $password = Configure::read('linnwork_api_password');
     $multi = AuthMethods::Multilogin($username, $password);
     $auth = AuthMethods::Authorize($username, $password, $multi[0]->Id);
     $token = $auth->Token;
     $server = $auth->Server;
     $openorder = OrdersMethods::GetOpenOrders('100', '1', '', '', '00000000-0000-0000-0000-000000000000', '', $token, $server);
     foreach ($openorder->Data as $orderids) {
         $orders[] = $orderids->OrderId;
     }
     $results = OrdersMethods::GetOrders($orders, '00000000-0000-0000-0000-000000000000', true, true, $token, $server);
     $countryArray = array('Austria' => 'Austria', 'Belgium' => 'Belgium', 'Bulgaria' => 'Bulgaria', 'Croatia' => 'Croatia', 'Cyprus' => 'Cyprus', 'Czech Republic' => 'Czech Republic', 'Denmark' => 'Denmark', 'Estonia' => 'Estonia', 'Finland' => 'Finland', 'France' => 'France', 'Germany' => 'Germany', 'Greece' => 'Greece', 'Hungary' => 'Hungary', 'Ireland' => 'Ireland', 'Italy' => 'Italy', 'Latvia' => 'Latvia', 'Lithuania' => 'Lithuania', 'Luxembourg' => 'Luxembourg', 'Malta' => 'Malta', 'Netherlands' => 'Netherlands', 'Poland' => 'Poland', 'Portugal' => 'Portugal', 'Romania' => 'Romania', 'Slovakia' => 'Slovakia', 'Slovenia' => 'Slovenia', 'Spain' => 'Spain', 'Sweden' => 'Sweden', 'United Kingdom' => 'United Kingdom');
     foreach ($results as $result) {
         if (($result->GeneralInfo->Status == 1 || $result->GeneralInfo->Status == 4) && $result->GeneralInfo->HoldOrCancel == '') {
             $data['order_id'] = $result->OrderId;
             $data['num_order_id'] = $result->NumOrderId;
             $data['general_info'] = serialize($result->GeneralInfo);
             $data['shipping_info'] = serialize($result->ShippingInfo);
             $data['customer_info'] = serialize($result->CustomerInfo);
             $data['totals_info'] = serialize($result->TotalsInfo);
             $data['folder_name'] = serialize($result->FolderName);
             $data['items'] = serialize($result->Items);
             //Extra information will save my according to manage sorting station section
             $country = $data['destination'] = $result->CustomerInfo->Address->Country;
             $orderitems = unserialize($data['items']);
             $this->OpenOrder->create();
             $checkorder = $this->OpenOrder->find('all', array('conditions' => array('OpenOrder.order_id' => $result->OrderId)));
             if (count($checkorder) > 0) {
             } else {
                 $this->OpenOrder->save($data);
                 //pr($orderitems);
                 /***************** split the order item ******************/
                 foreach ($orderitems as $orderitem) {
                     echo $orderitem->SKU . '==' . $orderitem->PricePerUnit;
                     echo "<br>";
                     $splitskus = explode('-', $orderitem->SKU);
                     $count = count($splitskus);
                     //Find Country
                     if (in_array($country, $countryArray)) {
                         //It means, Inside EU country shipping for bundle with sameSKU
                         if ($splitskus['0'] == 'B') {
                             for ($i = 1; $i <= count($splitskus) - 2; $i++) {
                                 if ($count == 3) {
                                     echo $value = $orderitem->Quantity * $orderitem->PricePerUnit * 1.38;
                                     echo "<br>";
                                     //For Euro
                                     if ($value < 35) {
                                         $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                         $splititem['product_sku_identifier'] = "single";
                                         $splititem['price'] = $orderitem->PricePerUnit;
                                         $splititem['quantity'] = $orderitem->Quantity;
                                         $splititem['product_type'] = "bundle";
                                         $splititem['order_id'] = $result->NumOrderId;
                                         $splititem['sku'] = 'S-' . $splitskus[$i];
                                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                         $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                         $this->OrderItem->create();
                                         $this->OrderItem->save($splititem);
                                     } else {
                                         if ($value <= 150 && $value >= 35) {
                                             $total = 0;
                                             $perUnitPrice = $orderitem->PricePerUnit;
                                             $orderQuantity = $orderitem->Quantity;
                                             $inc = 0;
                                             $bundleIdentity = 0;
                                             if ($splitskus[$count - 1] > 1) {
                                                 //It will be the same as Linnworks custom script term , So now will split the orders with SEQUENCING
                                                 $e = 0;
                                                 while ($e <= $orderQuantity - 1) {
                                                     $total = $total + 1.38 * $perUnitPrice;
                                                     if ($total <= 35) {
                                                         echo "Indes is :: " . $e . " <> Start ::" . $total;
                                                         echo "<br>";
                                                         $inc++;
                                                     } else {
                                                         echo "Indes is :: " . $e . " <> Bigger ::" . $total;
                                                         echo "<br>";
                                                         //Store previous then initialized
                                                         $bundleIdentity++;
                                                         //Store and split the same SKU bundle order
                                                         $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                         $splititem['product_sku_identifier'] = "single";
                                                         $splititem['price'] = $orderitem->PricePerUnit;
                                                         $splititem['product_order_id_identify'] = $result->NumOrderId;
                                                         $splititem['quantity'] = $inc;
                                                         $splititem['product_type'] = "bundle";
                                                         $splititem['order_id'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                         $splititem['sku'] = 'S-' . $splitskus[$i];
                                                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                         $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                         $total = 0;
                                                         $total = $total + 1.38 * $perUnitPrice;
                                                         $inc = 1;
                                                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                         $this->OrderItem->create();
                                                         $this->OrderItem->save($splititem);
                                                         if ($e == $orderQuantity - 1) {
                                                             //Store previous then initialized
                                                             $bundleIdentity++;
                                                             $inc = 1;
                                                             //Store and split the same SKU bundle order
                                                             $splititem['pack_order_quantity'] = $splitskus[$count - 1];
                                                             $splititem['product_sku_identifier'] = "single";
                                                             $splititem['price'] = $orderitem->PricePerUnit;
                                                             $splititem['product_order_id_identify'] = $result->NumOrderId;
                                                             $splititem['quantity'] = $inc;
                                                             $splititem['product_type'] = "bundle";
                                                             $splititem['order_id'] = $result->NumOrderId . '-' . $bundleIdentity;
                                                             $splititem['sku'] = 'S-' . $splitskus[$i];
                                                             $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                                                             $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                                                             $total = 0;
                                                             $total = $total + 1.38 * $perUnitPrice;
                                                             $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                                                             $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                                                             $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                                                             $this->OrderItem->create();
                                                             $this->OrderItem->save($splititem);
                                                         }
                                                     }
                                                     $e++;
                                                 }
                                             }
                                         } else {
                                             //echo "Exceed Limit to split."; exit;
                                         }
                                     }
                                 } else {
                                     //Handle Multiple Sku with type bundle
                                 }
                             }
                         } else {
                             $itemdata['price'] = $orderitem->PricePerUnit;
                             $itemdata['product_type'] = "single";
                             $itemdata['order_id'] = $result->NumOrderId;
                             $itemdata['sku'] = $orderitem->SKU;
                             $itemdata['quantity'] = $orderitem->Quantity;
                             $itemdata['barcode'] = $orderitem->BarcodeNumber;
                             $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $itemdata['sku'])));
                             $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $itemdata['quantity'];
                             $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $itemdata['quantity'];
                             $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $itemdata['sku']));
                             $this->OrderItem->create();
                             $this->OrderItem->save($itemdata);
                         }
                     } else {
                         //It means, Outside EU country shipping
                     }
                     /*************************************************************************/
                     /*if($splitskus['0'] == 'B')
                     		{
                     			for( $i = 1; $i <= count($splitskus)-2 ; $i++ )
                     			{
                     				if( $count == 3 )
                     				{
                     					$splititem['pack_order_quantity']		=	$splitskus[$count-1];
                     					$splititem['product_sku_identifier']		= "single";			
                     					$splititem['price']		=	$orderitem->PricePerUnit;
                     					
                     					$splititem['quantity']			=	$orderitem->Quantity;
                     					$splititem['product_type']		=	"bundle";
                     					$splititem['order_id']		=	$result->NumOrderId;
                     					$splititem['sku']			=	'S-'.$splitskus[$i];
                     					$productDetail				=	$this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'] )));
                     					$splititem['barcode']		=	$productDetail['ProductDesc']['barcode'];
                     					
                     					$productDetail['Product']['current_stock_level']	= $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                     					$productDetail['Product']['lock_qty']				= $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                     					
                     					$this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']),
                     												array('Product.product_sku' => $splititem['sku']));
                     					$this->OrderItem->create();
                     					$this->OrderItem->save( $splititem );								
                     					
                     				}
                     				else
                     				{
                     					$splititem['pack_order_quantity']			=	$splitskus[$count];	
                     					$splititem['product_sku_identifier']		= "multiple";
                     					$splititem['price']		=	$orderitem->PricePerUnit;																													
                     					
                     					$splititem['quantity']			=	$orderitem->Quantity;
                     					$splititem['product_type']		=	"bundle";
                     					$splititem['order_id']		=	$result->NumOrderId;
                     					$splititem['sku']			=	'S-'.$splitskus[$i];
                     					$productDetail				=	$this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'] )));
                     					$splititem['barcode']		=	$productDetail['ProductDesc']['barcode'];
                     					
                     					$productDetail['Product']['current_stock_level']	= $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                     					$productDetail['Product']['lock_qty']				= $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                     					
                     					$this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']),
                     												array('Product.product_sku' => $splititem['sku']));
                     					$this->OrderItem->create();
                     					$this->OrderItem->save( $splititem );
                     				}										
                     			}
                     		}
                     		else
                     		{
                     			$itemdata	['price']			=	$orderitem->PricePerUnit;								
                     			$itemdata['product_type']		=	"single";
                     			$itemdata['order_id']			=	$result->NumOrderId;
                     			$itemdata['sku']				=	$orderitem->SKU;
                     			$itemdata['quantity']			=	$orderitem->Quantity;
                     			$itemdata['barcode']			=	$orderitem->BarcodeNumber;
                     			
                     			$productDetail				=	$this->Product->find('first', array('conditions' => array('Product.product_sku' => $itemdata['sku'] )));
                     			$productDetail['Product']['current_stock_level']	= $productDetail['Product']['current_stock_level'] - $itemdata['quantity'];
                     			$productDetail['Product']['lock_qty']				= $productDetail['Product']['lock_qty'] + $itemdata['quantity'];
                     			$this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']),
                     											array('Product.product_sku' => $itemdata['sku']));
                     			$this->OrderItem->create();
                     			$this->OrderItem->save( $itemdata );
                     		}*/
                 }
                 /***********************************/
                 /*foreach( $orderitems as $orderitem )
                 		{
                 			$itemdata['order_id']			=	$result->NumOrderId;
                 			$itemdata['sku']				=	$orderitem->SKU;
                 			$itemdata['quantity']			=	$orderitem->Quantity;
                 			$itemdata['barcode']			=	$orderitem->BarcodeNumber;
                 			$this->OrderItem->create();
                 			$this->OrderItem->save( $itemdata );
                 		}*/
                 // code for save customer detail
                 $customerInfo['Customer']['email'] = $result->CustomerInfo->Address->EmailAddress;
                 $customerInfo['Customer']['address1'] = $result->CustomerInfo->Address->Address1;
                 $customerInfo['Customer']['address2'] = $result->CustomerInfo->Address->Address2;
                 $customerInfo['Customer']['address3'] = $result->CustomerInfo->Address->Address3;
                 $customerInfo['Customer']['town'] = $result->CustomerInfo->Address->Town;
                 $customerInfo['Customer']['region'] = $result->CustomerInfo->Address->Region;
                 $customerInfo['Customer']['postcode'] = $result->CustomerInfo->Address->PostCode;
                 $customerInfo['Customer']['country'] = $result->CustomerInfo->Address->Country;
                 $customerInfo['Customer']['name'] = $result->CustomerInfo->Address->FullName;
                 $customerInfo['Customer']['company'] = $result->CustomerInfo->Address->Company;
                 $customerInfo['Customer']['phone'] = $result->CustomerInfo->Address->PhoneNumber;
                 $customerInfo['Customer']['source'] = $result->GeneralInfo->Source;
                 $customerInfo['Customer']['subsource'] = $result->GeneralInfo->SubSource;
                 $customerdetails = $this->Customer->find('first', array('conditions' => array('Customer.email' => $customerInfo['Customer']['email'])));
                 if (count($customerdetails) > 0) {
                     //$customerdetails['Customer']['count'] = $customerdetails['Customer']['count'] + '1';
                     $this->Customer->updateAll(array('Customer.order_id' => $result->NumOrderId), array('Customer.email' => $customerdetails['Customer']['email']));
                 } else {
                     $customerInfo['Customer']['order_id'] = $result->NumOrderId;
                     $this->Customer->create();
                     $this->Customer->saveAll($customerInfo);
                 }
             }
         } else {
             //Do something you required
         }
     }
     /* call the function for assign the postal servises */
     $this->assign_services();
     $this->getBarcode();
     $this->setAgainAssignedServiceToAllOrder();
     // Euraco Group
     App::import('Controller', 'Products');
     $productModel = new ProductsController();
     $productModel->prepareVirtualStock();
 }
 /**
  * Tests ProductsController->deleteAction()
  */
 public function testDeleteAction()
 {
     // TODO Auto-generated ProductsControllerTest->testDeleteAction()
     $this->markTestIncomplete("deleteAction test not implemented");
     $this->ProductsController->deleteAction();
 }
Exemplo n.º 8
0
 public function saveorderdetail()
 {
     $this->layout = 'index';
     $this->autoRender = false;
     $this->loadModel('OpenOrder');
     $this->loadModel('AssignService');
     $this->loadModel('Customer');
     $this->loadModel('OrderItem');
     $this->loadModel('Product');
     App::import('Vendor', 'linnwork/api/Auth');
     App::import('Vendor', 'linnwork/api/Factory');
     App::import('Vendor', 'linnwork/api/Orders');
     $username = Configure::read('linnwork_api_username');
     $password = Configure::read('linnwork_api_password');
     $multi = AuthMethods::Multilogin($username, $password);
     $auth = AuthMethods::Authorize($username, $password, $multi[0]->Id);
     $token = $auth->Token;
     $server = $auth->Server;
     $openorder = OrdersMethods::GetOpenOrders('100', '1', '', '', '00000000-0000-0000-0000-000000000000', '', $token, $server);
     foreach ($openorder->Data as $orderids) {
         $orders[] = $orderids->OrderId;
     }
     $results = OrdersMethods::GetOrders($orders, '00000000-0000-0000-0000-000000000000', true, true, $token, $server);
     foreach ($results as $result) {
         if ($result->GeneralInfo->status = 1 && $result->GeneralInfo->HoldOrCancel == '') {
             $data['order_id'] = $result->OrderId;
             $data['num_order_id'] = $result->NumOrderId;
             $data['general_info'] = serialize($result->GeneralInfo);
             $data['shipping_info'] = serialize($result->ShippingInfo);
             $data['customer_info'] = serialize($result->CustomerInfo);
             $data['totals_info'] = serialize($result->TotalsInfo);
             $data['folder_name'] = serialize($result->FolderName);
             $data['items'] = serialize($result->Items);
             //Extra information will save my according to manage sorting station section
             $data['destination'] = $result->CustomerInfo->Address->Country;
             $orderitems = unserialize($data['items']);
             $this->OpenOrder->create();
             $checkorder = $this->OpenOrder->find('all', array('conditions' => array('OpenOrder.order_id' => $result->OrderId)));
             if (count($checkorder) > 0) {
             } else {
                 $this->OpenOrder->save($data);
                 /***************** split the order item ******************/
                 foreach ($orderitems as $orderitem) {
                     $splitskus = explode('-', $orderitem->SKU);
                     $count = count($splitskus);
                     if ($splitskus['0'] == 'B') {
                         for ($i = 1; $i <= count($splitskus) - 2; $i++) {
                             if ($count == 3) {
                                 $splititem['quantity'] = $splitskus[$count - 1];
                             } else {
                                 $splititem['quantity'] = $orderitem->Quantity;
                             }
                             $splititem['order_id'] = $result->NumOrderId;
                             $splititem['sku'] = 'S-' . $splitskus[$i];
                             $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $splititem['sku'])));
                             $splititem['barcode'] = $productDetail['ProductDesc']['barcode'];
                             $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $splititem['quantity'];
                             $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $splititem['quantity'];
                             $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $splititem['sku']));
                             $this->OrderItem->create();
                             $this->OrderItem->save($splititem);
                         }
                     } else {
                         $itemdata['order_id'] = $result->NumOrderId;
                         $itemdata['sku'] = $orderitem->SKU;
                         $itemdata['quantity'] = $orderitem->Quantity;
                         $itemdata['barcode'] = $orderitem->BarcodeNumber;
                         $productDetail = $this->Product->find('first', array('conditions' => array('Product.product_sku' => $itemdata['sku'])));
                         $productDetail['Product']['current_stock_level'] = $productDetail['Product']['current_stock_level'] - $itemdata['quantity'];
                         $productDetail['Product']['lock_qty'] = $productDetail['Product']['lock_qty'] + $itemdata['quantity'];
                         $this->Product->updateAll(array('Product.current_stock_level' => $productDetail['Product']['current_stock_level'], 'Product.lock_qty' => $productDetail['Product']['lock_qty']), array('Product.product_sku' => $itemdata['sku']));
                         $this->OrderItem->create();
                         $this->OrderItem->save($itemdata);
                     }
                 }
                 /***********************************/
                 /*foreach( $orderitems as $orderitem )
                 		{
                 			$itemdata['order_id']			=	$result->NumOrderId;
                 			$itemdata['sku']				=	$orderitem->SKU;
                 			$itemdata['quantity']			=	$orderitem->Quantity;
                 			$itemdata['barcode']			=	$orderitem->BarcodeNumber;
                 			$this->OrderItem->create();
                 			$this->OrderItem->save( $itemdata );
                 		}*/
                 // code for save customer detail
                 $customerInfo['Customer']['email'] = $result->CustomerInfo->Address->EmailAddress;
                 $customerInfo['Customer']['address1'] = $result->CustomerInfo->Address->Address1;
                 $customerInfo['Customer']['address2'] = $result->CustomerInfo->Address->Address2;
                 $customerInfo['Customer']['address3'] = $result->CustomerInfo->Address->Address3;
                 $customerInfo['Customer']['town'] = $result->CustomerInfo->Address->Town;
                 $customerInfo['Customer']['region'] = $result->CustomerInfo->Address->Region;
                 $customerInfo['Customer']['postcode'] = $result->CustomerInfo->Address->PostCode;
                 $customerInfo['Customer']['country'] = $result->CustomerInfo->Address->Country;
                 $customerInfo['Customer']['name'] = $result->CustomerInfo->Address->FullName;
                 $customerInfo['Customer']['company'] = $result->CustomerInfo->Address->Company;
                 $customerInfo['Customer']['phone'] = $result->CustomerInfo->Address->PhoneNumber;
                 $customerInfo['Customer']['source'] = $result->GeneralInfo->Source;
                 $customerInfo['Customer']['subsource'] = $result->GeneralInfo->SubSource;
                 $customerdetails = $this->Customer->find('first', array('conditions' => array('Customer.email' => $customerInfo['Customer']['email'])));
                 if (count($customerdetails) > 0) {
                     //$customerdetails['Customer']['count'] = $customerdetails['Customer']['count'] + '1';
                     $this->Customer->updateAll(array('Customer.order_id' => $result->NumOrderId), array('Customer.email' => $customerdetails['Customer']['email']));
                 } else {
                     $customerInfo['Customer']['order_id'] = $result->NumOrderId;
                     $this->Customer->create();
                     $this->Customer->saveAll($customerInfo);
                 }
             }
         }
     }
     /* call the function for assign the postal servises */
     $this->assign_services();
     $this->getBarcode();
     $this->setAgainAssignedServiceToAllOrder();
     // Euraco Group
     App::import('Controller', 'Products');
     $productModel = new ProductsController();
     $productModel->prepareVirtualStock();
 }
 /**
  * Build display of products from search results, default, etc.
  * 
  * @param $results - array of 'Product' items from search results
  * @param $params - array of additional view variables to send (e.g.,
  *          search criteria, workshop year selection, etc.)
  * 
  * @return Response
  */
 private function makeIndexView($results, $params)
 {
     // Paginate the results of the custom query by using 'Paginator::make()'.
     // http://stackoverflow.com/a/23881516
     $paginator = json_decode($results);
     $perPage = 20;
     $page = Input::get('page', 1);
     if ($page > count($paginator) or $page < 1) {
         $page = 1;
     }
     $offset = $page * $perPage - $perPage;
     $dataSubset = array_slice($paginator, $offset, $perPage);
     $products = Paginator::make($dataSubset, count($paginator), $perPage);
     $params['heading'] = 'Product List';
     $params['workshop_year_list'] = ProductsController::getWorkshopYearList();
     $params['orderVerification'] = FALSE;
     $params['mp3_tooltip'] = "Enable/check to order MP3 for \$" . \Config::get('workshop.unit_price_list')['MP3'] . " instead of CD.";
     if (!isset($params['workshop_year_selected'])) {
         $params['workshop_year_selected'] = Config::get('workshop.current_workshop_year');
     }
     if (!isset($params['search_year_ind'])) {
         $params['search_year_ind'] = 'All';
     }
     if (!isset($params['search_criteria'])) {
         $params['search_criteria'] = NULL;
     }
     $this->layout->content = View::make('products.index', compact('products'))->with($params);
 }
Exemplo n.º 10
0
 public function productVirtualStockCsvGeneration()
 {
     $this->layout = '';
     $this->autoRender = false;
     $getBase = Router::url('/', true);
     $getStockDetail = json_decode(json_encode(ProductsController::getStockDataForCsv()), 0);
     //pr($getStockDetail); exit;
     /*
      * 
      * Params, To setup virtual stock for upload over linnworks where it will update on each platform, 
      * that we are using ( Amazon, Ebay , Magento etc etc )
      * 
      */
     ob_clean();
     App::import('Vendor', 'PHPExcel/IOFactory');
     App::import('Vendor', 'PHPExcel');
     $objPHPExcel = new PHPExcel();
     //Column Create
     $objPHPExcel->setActiveSheetIndex(0);
     $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Product Title');
     $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Product Sku');
     $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Barcode');
     $objPHPExcel->getActiveSheet()->setCellValue('D1', 'Stock');
     $objPHPExcel->getActiveSheet()->setCellValue('E1', 'Original Stock');
     $inc = 2;
     $e = 0;
     foreach ($getStockDetail as $getStockDetailIndex => $getStockDetailValue) {
         if (strtolower($getStockDetailValue->ProductDesc->product_type) === "single") {
             $objPHPExcel->getActiveSheet()->setCellValue('A' . $inc, addslashes($getStockDetailValue->Product->ProductTitle));
             $objPHPExcel->getActiveSheet()->setCellValue('B' . $inc, addslashes($getStockDetailValue->Product->MainSku));
             $objPHPExcel->getActiveSheet()->setCellValue('C' . $inc, addslashes($getStockDetailValue->ProductDesc->barcode));
             if ($getStockDetailValue->Product->AvailableStock == '' || $getStockDetailValue->Product->AvailableStock == 0) {
                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $inc, 0);
                 //Set highlight full row
                 $objPHPExcel->getActiveSheet(0)->getStyle('A' . $inc . ':E' . $inc)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'D83C3C'))));
             } else {
                 $objPHPExcel->getActiveSheet()->setCellValue('D' . $inc, $getStockDetailValue->Product->AvailableStock);
             }
             $objPHPExcel->getActiveSheet()->setCellValue('E' . $inc, $getStockDetailValue->Product->AvailableStock);
         } elseif (strtolower($getStockDetailValue->ProductDesc->product_type) === "bundle") {
             if (strtolower($getStockDetailValue->ProductDesc->product_identifier) === "single") {
                 //Set if same sku is there with single-bundle type
                 $this->Product->unbindModel(array('hasOne' => array('ProductDesc', 'ProductPrice'), 'hasMany' => array('ProductLocation')));
                 $this->ProductDesc->unbindModel(array('belongsTo' => array('Product')));
                 $params = array('conditions' => array('Product.product_sku' => $getStockDetailValue->ProductDesc->product_defined_skus), 'fields' => array('IF(Product.current_stock_level > 2, Product.current_stock_level , 0) as FindStockThrough__LimitFactor'), 'order' => 'Product.id ASC');
                 $stockData = json_decode(json_encode($this->Product->find('all', $params)), 0);
                 $getDivisionNumberFromBundleSku = explode('-', $getStockDetailValue->Product->MainSku)[2];
                 $index = 0;
                 $getAvailableStockFor_Bundle_WithSameSku = $stockData[0][$index]->FindStockThrough__LimitFactor;
                 //Set data into file
                 $objPHPExcel->getActiveSheet()->setCellValue('A' . $inc, addslashes($getStockDetailValue->Product->ProductTitle));
                 $objPHPExcel->getActiveSheet()->setCellValue('B' . $inc, addslashes($getStockDetailValue->Product->MainSku));
                 $objPHPExcel->getActiveSheet()->setCellValue('C' . $inc, addslashes($getStockDetailValue->ProductDesc->barcode));
                 if ($getAvailableStockFor_Bundle_WithSameSku > 2) {
                     $getAvailableStockFor_Bundle_WithSameSku = round($getAvailableStockFor_Bundle_WithSameSku / $getDivisionNumberFromBundleSku) - 2;
                     $objPHPExcel->getActiveSheet()->setCellValue('D' . $inc, $getAvailableStockFor_Bundle_WithSameSku);
                 } else {
                     $objPHPExcel->getActiveSheet()->setCellValue('D' . $inc, 0);
                     //Set highlight full row
                     $objPHPExcel->getActiveSheet(0)->getStyle('A' . $inc . ':E' . $inc)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'D83C3C'))));
                 }
                 $objPHPExcel->getActiveSheet()->setCellValue('E' . $inc, $stockData[0][$index]->FindStockThrough__LimitFactor);
             } elseif (strtolower($getStockDetailValue->ProductDesc->product_identifier) === "multiple") {
                 //Set if different sku will manipulate over limit factor
                 $this->Product->unbindModel(array('hasOne' => array('ProductDesc', 'ProductPrice'), 'hasMany' => array('ProductLocation')));
                 $params = array('conditions' => array('ProductDesc.product_defined_skus' => $getStockDetailValue->ProductDesc->product_defined_skus), 'fields' => array('ProductDesc.product_defined_skus as Diff_Skus'), 'order' => 'ProductDesc.id ASC');
                 $stockData = json_decode(json_encode($this->ProductDesc->find('all', $params)), 0);
                 $diff_SkuList = explode(':', $stockData[0]->ProductDesc->Diff_Skus);
                 //Get Diff Sku stock value under min section according to limit factor
                 //Set if same sku is there with single-bundle type
                 $this->Product->unbindModel(array('hasOne' => array('ProductDesc', 'ProductPrice'), 'hasMany' => array('ProductLocation')));
                 $this->ProductDesc->unbindModel(array('belongsTo' => array('Product')));
                 $params = array('conditions' => array('Product.product_sku' => $diff_SkuList), 'fields' => array('Product.id', 'Product.current_stock_level'), 'order' => 'Product.id ASC');
                 //Get relevant data
                 $getListStockValue = $this->Product->find('list', $params);
                 $stockDataValue = min($getListStockValue);
                 //Here we have found min lowest stock sku value tha means, need to put it into csv but keep safety margin
                 if ($stockDataValue > 2) {
                     //If greater then will need to keep 2 for safety margin
                     //Set data into file
                     $objPHPExcel->getActiveSheet()->setCellValue('A' . $inc, addslashes($getStockDetailValue->Product->ProductTitle));
                     $objPHPExcel->getActiveSheet()->setCellValue('B' . $inc, addslashes($getStockDetailValue->Product->MainSku));
                     $objPHPExcel->getActiveSheet()->setCellValue('C' . $inc, addslashes($getStockDetailValue->ProductDesc->barcode));
                     $objPHPExcel->getActiveSheet()->setCellValue('D' . $inc, $stockDataValue - 2);
                     $objPHPExcel->getActiveSheet()->setCellValue('E' . $inc, implode($getListStockValue, ','));
                 } elseif ($stockDataValue <= 2) {
                     //If less or equal then will need to put space / blank
                     //Set data into file
                     $objPHPExcel->getActiveSheet()->setCellValue('A' . $inc, addslashes($getStockDetailValue->Product->ProductTitle));
                     $objPHPExcel->getActiveSheet()->setCellValue('B' . $inc, addslashes($getStockDetailValue->Product->MainSku));
                     $objPHPExcel->getActiveSheet()->setCellValue('C' . $inc, addslashes($getStockDetailValue->ProductDesc->barcode));
                     $objPHPExcel->getActiveSheet()->setCellValue('D' . $inc, 0);
                     $objPHPExcel->getActiveSheet()->setCellValue('E' . $inc, implode($getListStockValue, ','));
                     //Set highlight full row
                     $objPHPExcel->getActiveSheet(0)->getStyle('A' . $inc . ':E' . $inc)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'D83C3C'))));
                 }
             }
         }
         $e++;
         $inc++;
     }
     //File creation
     $objPHPExcel->getActiveSheet(0)->getStyle('A1:E1')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER));
     $objPHPExcel->getActiveSheet(0)->getStyle('A1:E1')->getAlignment()->setWrapText(true);
     $objPHPExcel->getActiveSheet(0)->setTitle('Virtual Stock');
     $objPHPExcel->getActiveSheet(0)->getStyle("A1:E1")->getFont()->setBold(true);
     $objPHPExcel->getActiveSheet(0)->getStyle('A1:E1')->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'EBE5DB'))));
     $uploadUrl = WWW_ROOT . 'img/stockUpdate/virtualStock.csv';
     //$uploadRemote = $getBase.'app/webroot/img/stockUpdate/virtualStock.csv';
     $uploadRemote = $getBase . 'img/stockUpdate/virtualStock.csv';
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
     $objWriter->save($uploadUrl);
     return $uploadRemote;
 }
Exemplo n.º 11
0
<?php

/*
 * -----------------------------
 * entrance of products component/产品管理组件入口程序
 * -----------------------------
 * @author HollenMok
 * @date 2015/09/05
 * 
 */
require 'controller.php';
$controller = new ProductsController();
if ($task) {
    $controller->{$task}();
} else {
    $controller->display();
}