コード例 #1
0
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = 'SELECT * FROM ' . $resource->getTableName('sales/order') . ' WHERE state NOT IN ("complete","canceled","new","closed")';
$orders = $readConnection->fetchAll($query);
$orderId = array();
foreach ($orders as $order) {
    $orderCode = $order['increment_id'];
    $orderState = $order['status'];
    $order['Code'] = $orderCode;
    $myPackageServiceGet = new MyPackageServiceGet($wsdl);
    $orderresponse = array();
    if ($myPackageServiceGet->GetSaleOrder(new MyPackageStructGetSaleOrderRequest($order))) {
        $orderresponse = $myPackageServiceGet->getResult();
        $sucessresponse = $orderresponse->Successful;
        $getorder = new MyPackageStructGetSaleOrderResponse($sucessresponse->Successful, $sucessresponse->Errors, $sucessresponse->Warnings, $sucessresponse->SaleOrder);
        if ($getorder->getSuccessful()) {
            $checkItemStatus = true;
            $statusCode = "";
            $chkcancelitem = false;
            if (count($getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem) > 0) {
                foreach ($getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem as $item) {
                    if ($statusCode !== "") {
                        if ($statusCode != $item->StatusCode) {
                            $checkItemStatus = false;
                        }
                    }
                    if ($item->StatusCode !== "CANCELLED") {
                        $unicom_skus[] = $item->ItemSKU;
                    } else {
                        $chkcancelitem = true;
                    }
コード例 #2
0
ファイル: Observer.php プロジェクト: shebin512/Magento_Zoff
 public function unicomOrderItemUpdate(Varien_Event_Observer $observer)
 {
     $orderlog = Mage::getBaseDir() . '/var/order/unicomstatus.log';
     $writer = new Zend_Log_Writer_Stream($orderlog);
     $logger = new Zend_Log($writer);
     $wsdlUrl = Mage::getStoreConfig('unicom_options/unigroup/uniurl');
     $wsdllUrl = Mage::getStoreConfig('unicom_options/unigroup/unilurl');
     $uniUname = Mage::getStoreConfig('unicom_options/unigroup/uniusername');
     $uniPass = Mage::getStoreConfig('unicom_options/unigroup/unipass');
     /*define('MYPACKAGE_WSDL_URL','https://demo.unicommerce.com/services/soap/uniware13.wsdl');
     		define('MYPACKAGE_USER_LOGIN','zoffio');
     		define('MYPACKAGE_USER_PASSWORD','zoff@uni1'); */
     define('MYPACKAGE_WSDL_URL', $wsdlUrl);
     define('MYPACKAGE_WSDL_LURL', $wsdllUrl);
     define('MYPACKAGE_USER_LOGIN', $uniUname);
     define('MYPACKAGE_USER_PASSWORD', $uniPass);
     $wsdl = array();
     $wsdl[MyPackageWsdlClass::WSDL_URL] = MYPACKAGE_WSDL_URL;
     $wsdl[MyPackageWsdlClass::WSDL_LURL] = MYPACKAGE_WSDL_LURL;
     $wsdl[MyPackageWsdlClass::WSDL_CACHE_WSDL] = WSDL_CACHE_NONE;
     $wsdl[MyPackageWsdlClass::WSDL_TRACE] = true;
     if (MYPACKAGE_USER_LOGIN !== '') {
         $wsdl[MyPackageWsdlClass::WSDL_LOGIN] = MYPACKAGE_USER_LOGIN;
     }
     if (MYPACKAGE_USER_PASSWORD !== '') {
         $wsdl[MyPackageWsdlClass::WSDL_PASSWD] = MYPACKAGE_USER_PASSWORD;
     }
     $resource = Mage::getSingleton('core/resource');
     $readConnection = $resource->getConnection('core_read');
     $query = 'SELECT * FROM ' . $resource->getTableName('sales/order') . ' WHERE status NOT IN ("complete","canceled","pending")';
     $orders = $readConnection->fetchAll($query);
     $orderId = array();
     foreach ($orders as $order) {
         $orderCode = $order['increment_id'];
         $orderState = $order['status'];
         $order['Code'] = $orderCode;
         $myPackageServiceGet = new MyPackageServiceGet($wsdl);
         $orderresponse = array();
         if ($myPackageServiceGet->GetSaleOrder(new MyPackageStructGetSaleOrderRequest($order))) {
             $orderresponse = $myPackageServiceGet->getResult();
             $sucessresponse = $orderresponse->Successful;
             $getorder = new MyPackageStructGetSaleOrderResponse($sucessresponse->Successful, $sucessresponse->Errors, $sucessresponse->Warnings, $sucessresponse->SaleOrder);
             if ($getorder->getSuccessful()) {
                 $checkItemStatus = true;
                 $statusCode = "";
                 $chkcancelitem = false;
                 if (count($getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem) > 0) {
                     foreach ($getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem as $item) {
                         if ($statusCode !== "") {
                             if ($statusCode != $item->StatusCode) {
                                 $checkItemStatus = false;
                             }
                         }
                         if ($item->StatusCode !== "CANCELLED") {
                             $unicom_skus[] = $item->ItemSKU;
                         } else {
                             $chkcancelitem = true;
                         }
                         $statusCode = $item->StatusCode;
                         if ($statusCode == "CREATED") {
                             $checkItemStatus = false;
                         }
                     }
                 } else {
                     $statusCode = $getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem->StatusCode;
                     if ($statusCode == "CREATED") {
                         $checkItemStatus = false;
                     }
                 }
                 if ($checkItemStatus == true) {
                     if ($statusCode == "FULFILLABLE" || $statusCode == "UNFULFILLABLE") {
                         $mageState = 'processing';
                         $mageStatus = 'Processing';
                     } elseif ($statusCode == "CANCELLED") {
                         $mageState = 'canceled';
                         $mageStatus = 'Canceled';
                     } elseif ($statusCode == "DISPATCHED") {
                         $mageState = 'shipped';
                         $mageStatus = 'Shipped';
                     } elseif ($statusCode == "DELIVERED") {
                         $mageState = 'complete';
                         $mageStatus = 'Complete';
                     } else {
                         $mageState = 'processing';
                         $mageStatus = 'Processing';
                     }
                     //Mage::log($orderCode."-Success",null,'orderstatus.log');
                     //$orderId = '141433271';
                     if (strtolower($orderState) != $mageState) {
                         if ($mageState == "complete") {
                             if ($chkcancelitem == true) {
                                 /*
                                 			$order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                                 			$items = $order->getItemsCollection();
                                 			$ordertotalqty = (int)$order->getTotalQtyOrdered();
                                 			$chordertotalqty = (int)$order->getTotalQtyOrdered();
                                 			$subTotal = $order->getSubtotal();
                                 			$basesubTotal = $order->getBaseSubtotal();
                                 			$taxAmount  = $order->getTaxAmount();
                                 			$basetaxAmount = $order->getBaseTaxAmount();
                                 			$grandtotal  = $order->getGrandTotal();
                                 			$ordersubtotal = '0.0000';
                                 			$ordertaxAmount = '0.0000';
                                 			$ordergrandtotal = '0.0000';
                                 $unicom_cntsku = array_count_values($unicom_skus);
                                 foreach ($items as $item) {
                                 				$itemSku = $item->getSku();
                                 				if (in_array($itemSku, $unicom_skus)) {
                                 					//reduce the item
                                 					$uqty = $unicom_cntsku[$itemSku];
                                 					$itemoqty = (int)$item->getQtyOrdered();
                                 					$chkitemqty2 = $itemoqty - $uqty;
                                 					$chkitemqty = $uqty;
                                 					if($chkitemqty2 > 0) {
                                 							$itemrowtotalincltax = $item->getOriginalPrice() * $chkitemqty;
                                 							$itemrowtotal = $itemrowtotalincltax / (1 + ($item->getTaxPercent()/100));
                                 							$itemrowtotal = round($itemrowtotal,2);
                                 							$itemtaxamount = $itemrowtotalincltax - $itemrowtotal;
                                 							$itemtaxamount = round($itemtaxamount,2);
                                 							$itemrowtotalincltax = round($itemrowtotalincltax,2);
                                 							if($chordertotalqty < $ordertotalqty) {
                                 								$ordersubtotal = ($ordersubtotal - $item->getRowTotal()) + $itemrowtotal;
                                 								$ordertaxAmount = ($ordertaxAmount - $item->getTaxAmount()) + $itemtaxamount;
                                 								$ordergrandtotal = ($ordergrandtotal - $item->getRowTotalInclTax()) + $itemrowtotalincltax;
                                 							} else {
                                 								$ordersubtotal = ($subTotal - $item->getRowTotal()) + $itemrowtotal;
                                 								$ordertaxAmount = ($taxAmount - $item->getTaxAmount()) + $itemtaxamount;
                                 								$ordergrandtotal = ($grandtotal - $item->getRowTotalInclTax()) + $itemrowtotalincltax;
                                 							}
                                 
                                 							$item->setQtyOrdered($chkitemqty);
                                 							$item->setQtyInvoiced('0.0000');
                                 							$item->setTaxAmount($itemtaxamount);
                                 							$item->setBaseTaxAmount($itemtaxamount);
                                 							$item->setRowTotal($itemrowtotal);
                                 							$item->setBaseRowTotal($itemrowtotal);
                                 							$item->setRowTotalInclTax($itemrowtotalincltax);
                                 							$item->setBaseRowTotalInclTax($itemrowtotalincltax);
                                 							if($item->getProductOptions()){
                                 							$proOptions = $item->getProductOptions();
                                 							$chkitemqty = $chkitemqty.".0000";
                                 							$proOptions['info_buyRequest']['qty'] = $chkitemqty;
                                 							$item->setProductOptions($proOptions);
                                 							}
                                 							$item->save();
                                 							if ($order->hasInvoices()) {
                                 								$resource = Mage::getSingleton('core/resource');
                                 								$readConnection = $resource->getConnection('core_read');
                                 								$query = 'SELECT entity_id FROM sales_flat_invoice_item WHERE order_item_id = '.$item->getItemId();
                                 								$invitemid = $readConnection->fetchAll($query);
                                 								$inviteid = $invitemid[0]['entity_id'];
                                 
                                 							$invoiceItem = Mage::getModel("sales/order_invoice_item")->load($inviteid);
                                 							$invoiceItem->setQty($item->getQtyOrdered());
                                 							$invoiceItem->setTaxAmount($item->getTaxAmount());
                                 							$invoiceItem->setBaseTaxAmount($item->getBaseTaxAmount());
                                 							$invoiceItem->setRowTotal($item->getRowTotal());
                                 							$invoiceItem->setBaseRowTotal($item->getBaseRowTotal());
                                 							$invoiceItem->setRowTotalInclTax($item->getRowTotalInclTax());
                                 							$invoiceItem->setBaseRowTotalInclTax($item->getBaseRowTotalInclTax());
                                 							$invoiceItem->save();
                                 							}
                                 							$item->setQtyInvoiced($item->getQtyOrdered());
                                 							$item->save();
                                 							$chordertotalqty = $ordertotalqty - $chkitemqty2;
                                 					}
                                 				} else {
                                 					
                                 					//delete the item
                                 					$itemoqty = (int)$item->getQtyOrdered();
                                 					if($chordertotalqty < $ordertotalqty) {
                                 					$chordertotalqty = $chordertotalqty - $itemoqty;
                                 					$ordersubtotal = $ordersubtotal - $item->getRowTotal();
                                 					$ordertaxAmount = $ordertaxAmount - $item->getTaxAmount();
                                 					$ordergrandtotal = $ordergrandtotal - $item->getRowTotalInclTax();
                                 					} else {
                                 					$chordertotalqty = $ordertotalqty - $itemoqty;
                                 					$ordersubtotal = $subTotal - $item->getRowTotal();
                                 					$ordertaxAmount = $taxAmount - $item->getTaxAmount();
                                 					$ordergrandtotal = $grandtotal - $item->getRowTotalInclTax();
                                 					}
                                 					$item->delete();
                                 					if ($order->hasInvoices()) {
                                 						$resource = Mage::getSingleton('core/resource');
                                 						$readConnection = $resource->getConnection('core_read');
                                 						$query = 'SELECT entity_id FROM sales_flat_invoice_item WHERE order_item_id = '.$item->getItemId();
                                 						$invitemid = $readConnection->fetchAll($query);
                                 						$inviteid = $invitemid[0]['entity_id'];
                                 
                                 						$invoiceItem = Mage::getModel("sales/order_invoice_item")->load($inviteid);					
                                 						$invoiceItem->delete();
                                 					}
                                 				}
                                 			}
                                 
                                 			if($chordertotalqty < $ordertotalqty) {
                                 				$order->setTotalQtyOrdered($chordertotalqty)
                                 					  ->setBaseTotalQtyOrdered($chordertotalqty)
                                 					  ->setSubtotal($ordersubtotal)
                                 					  ->setBaseSubtotal($ordersubtotal)
                                 					  ->setTaxAmount($ordertaxAmount)
                                 					  ->setBaseTaxAmount($ordertaxAmount)
                                 					  ->setGrandTotal($ordergrandtotal)
                                 					  ->setBaseGrandTotal($ordergrandtotal);
                                 				$order->save();
                                 				if ($order->hasInvoices()) {
                                 				$invIncrementIDs = array();
                                 				foreach ($order->getInvoiceCollection() as $inv) {
                                 					$invIncrementIDs[] = $inv->getIncrementId();
                                 				}
                                 
                                 				$invoice = Mage::getModel("sales/order_invoice")->loadByIncrementId($invIncrementIDs[0]);
                                 				$invoice->setTotalQty($chordertotalqty)
                                 							->setSubtotal($ordersubtotal)
                                 							->setBaseSubtotal($ordersubtotal)
                                 							->setTaxAmount($ordertaxAmount)
                                 							->setBaseTaxAmount($ordertaxAmount)
                                 							->setGrandTotal($ordergrandtotal)
                                 							->setBaseGrandTotal($ordergrandtotal);
                                 				$invoice->save();
                                 				$logger->info($orderCode."-invoice-update-Success");
                                 				}
                                 				$logger->info($orderCode."-Success");
                                 			}			
                                 */
                             }
                             $order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                             if (!$order->hasInvoices()) {
                                 $invoice = $order->prepareInvoice();
                                 $invoice->register();
                                 Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder())->save();
                                 $logger->info($orderCode . "-invoice-update-Success");
                             }
                         }
                         $order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                         $comment = 'Changing status to ' . $mageStatus . ' Status from unicom';
                         $isCustomerNotified = false;
                         $order->setState($mageState, $mageStatus, $comment, $isCustomerNotified);
                         $order->save();
                         //Mage::log($orderCode."-Success",null,'orderstatus.log');
                         $logger->info($orderCode . "-Success");
                     }
                 } else {
                     $myPackageServiceSearch = new MyPackageServiceSearch($wsdl);
                     if ($myPackageServiceSearch->SearchSaleOrder(new MyPackageStructSearchSaleOrderRequest($orderCode, NULL, NULL, NULL, NULL, NULL, NULL, new MyPackageStructSearchOptions(0)))) {
                         $getSearchOrder = $myPackageServiceSearch->getResult();
                         $statusCode = $getSearchOrder->Successful->SaleOrders->SaleOrder->Status;
                         if ($statusCode != "CREATED" && $statusCode != "PENDING_VERIFICATION") {
                             if ($statusCode == "PROCESSING") {
                                 $mageState = 'processing';
                                 $mageStatus = 'Processing';
                             } elseif ($statusCode == "CANCELLED") {
                                 $mageState = 'canceled';
                                 $mageStatus = 'Canceled';
                             } elseif ($statusCode == "COMPLETE") {
                                 $mageState = 'complete';
                                 $mageStatus = 'Complete';
                             } else {
                                 $statecount = count($getSearchOrder->Successful->SaleOrders->SaleOrder);
                                 if ($statecount > 1) {
                                     $statusCode = $getSearchOrder->Successful->SaleOrders->SaleOrder[0]->Status;
                                     if ($statusCode == "COMPLETE") {
                                         $mageState = 'complete';
                                         $mageStatus = 'Complete';
                                     } else {
                                         $mageState = 'processing';
                                         $mageStatus = 'Processing';
                                     }
                                 }
                             }
                             if ($mageState == "complete") {
                                 if ($chkcancelitem == true) {
                                     /*			
                                     			$order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                                     			$items = $order->getItemsCollection();
                                     			$ordertotalqty = (int)$order->getTotalQtyOrdered();
                                     			$chordertotalqty = (int)$order->getTotalQtyOrdered();
                                     			$subTotal = $order->getSubtotal();
                                     			$basesubTotal = $order->getBaseSubtotal();
                                     			$taxAmount  = $order->getTaxAmount();
                                     			$basetaxAmount = $order->getBaseTaxAmount();
                                     			$grandtotal  = $order->getGrandTotal();
                                     			$ordersubtotal = '0.0000';
                                     			$ordertaxAmount = '0.0000';
                                     			$ordergrandtotal = '0.0000';
                                     $unicom_cntsku = array_count_values($unicom_skus);
                                     foreach ($items as $item) {
                                     				$itemSku = $item->getSku();
                                     				if (in_array($itemSku, $unicom_skus)) {
                                     					//reduce the item
                                     					$uqty = $unicom_cntsku[$itemSku];
                                     					$itemoqty = (int)$item->getQtyOrdered();
                                     					$chkitemqty2 = $itemoqty - $uqty;
                                     					$chkitemqty = $uqty;
                                     					if($chkitemqty2 > 0) {
                                     							$itemrowtotalincltax = $item->getOriginalPrice() * $chkitemqty;
                                     							$itemrowtotal = $itemrowtotalincltax / (1 + ($item->getTaxPercent()/100));
                                     							$itemrowtotal = round($itemrowtotal,2);
                                     							$itemtaxamount = $itemrowtotalincltax - $itemrowtotal;
                                     							$itemtaxamount = round($itemtaxamount,2);
                                     							$itemrowtotalincltax = round($itemrowtotalincltax,2);
                                     							if($chordertotalqty < $ordertotalqty) {
                                     								$ordersubtotal = ($ordersubtotal - $item->getRowTotal()) + $itemrowtotal;
                                     								$ordertaxAmount = ($ordertaxAmount - $item->getTaxAmount()) + $itemtaxamount;
                                     								$ordergrandtotal = ($ordergrandtotal - $item->getRowTotalInclTax()) + $itemrowtotalincltax;
                                     							} else {
                                     								$ordersubtotal = ($subTotal - $item->getRowTotal()) + $itemrowtotal;
                                     								$ordertaxAmount = ($taxAmount - $item->getTaxAmount()) + $itemtaxamount;
                                     								$ordergrandtotal = ($grandtotal - $item->getRowTotalInclTax()) + $itemrowtotalincltax;
                                     							}
                                     
                                     							$item->setQtyOrdered($chkitemqty);
                                     							$item->setQtyInvoiced('0.0000');
                                     							$item->setTaxAmount($itemtaxamount);
                                     							$item->setBaseTaxAmount($itemtaxamount);
                                     							$item->setRowTotal($itemrowtotal);
                                     							$item->setBaseRowTotal($itemrowtotal);
                                     							$item->setRowTotalInclTax($itemrowtotalincltax);
                                     							$item->setBaseRowTotalInclTax($itemrowtotalincltax);
                                     							if($item->getProductOptions()){
                                     							$proOptions = $item->getProductOptions();
                                     							$chkitemqty = $chkitemqty.".0000";
                                     							$proOptions['info_buyRequest']['qty'] = $chkitemqty;
                                     							$item->setProductOptions($proOptions);
                                     							}
                                     							$item->save();
                                     							if ($order->hasInvoices()) {
                                     								$resource = Mage::getSingleton('core/resource');
                                     								$readConnection = $resource->getConnection('core_read');
                                     								$query = 'SELECT entity_id FROM sales_flat_invoice_item WHERE order_item_id = '.$item->getItemId();
                                     								$invitemid = $readConnection->fetchAll($query);
                                     								$inviteid = $invitemid[0]['entity_id'];
                                     
                                     							$invoiceItem = Mage::getModel("sales/order_invoice_item")->load($inviteid);
                                     							$invoiceItem->setQty($item->getQtyOrdered());
                                     							$invoiceItem->setTaxAmount($item->getTaxAmount());
                                     							$invoiceItem->setBaseTaxAmount($item->getBaseTaxAmount());
                                     							$invoiceItem->setRowTotal($item->getRowTotal());
                                     							$invoiceItem->setBaseRowTotal($item->getBaseRowTotal());
                                     							$invoiceItem->setRowTotalInclTax($item->getRowTotalInclTax());
                                     							$invoiceItem->setBaseRowTotalInclTax($item->getBaseRowTotalInclTax());
                                     							$invoiceItem->save();
                                     							}
                                     							$item->setQtyInvoiced($item->getQtyOrdered());
                                     							$item->save();
                                     							$chordertotalqty = $ordertotalqty - $chkitemqty2;
                                     					}
                                     				} else {
                                     					
                                     					//delete the item
                                     					$itemoqty = (int)$item->getQtyOrdered();
                                     					if($chordertotalqty < $ordertotalqty) {
                                     					$chordertotalqty = $chordertotalqty - $itemoqty;
                                     					$ordersubtotal = $ordersubtotal - $item->getRowTotal();
                                     					$ordertaxAmount = $ordertaxAmount - $item->getTaxAmount();
                                     					$ordergrandtotal = $ordergrandtotal - $item->getRowTotalInclTax();
                                     					} else {
                                     					$chordertotalqty = $ordertotalqty - $itemoqty;
                                     					$ordersubtotal = $subTotal - $item->getRowTotal();
                                     					$ordertaxAmount = $taxAmount - $item->getTaxAmount();
                                     					$ordergrandtotal = $grandtotal - $item->getRowTotalInclTax();
                                     					}
                                     					$item->delete();
                                     					if ($order->hasInvoices()) {
                                     						$resource = Mage::getSingleton('core/resource');
                                     						$readConnection = $resource->getConnection('core_read');
                                     						$query = 'SELECT entity_id FROM sales_flat_invoice_item WHERE order_item_id = '.$item->getItemId();
                                     						$invitemid = $readConnection->fetchAll($query);
                                     						$inviteid = $invitemid[0]['entity_id'];
                                     
                                     						$invoiceItem = Mage::getModel("sales/order_invoice_item")->load($inviteid);					
                                     						$invoiceItem->delete();
                                     					}
                                     				}
                                     				$logger->info($orderCode."-invoice-update-Success");
                                     			}
                                     
                                     			if($chordertotalqty < $ordertotalqty) {
                                     				$order->setTotalQtyOrdered($chordertotalqty)
                                     					  ->setBaseTotalQtyOrdered($chordertotalqty)
                                     					  ->setSubtotal($ordersubtotal)
                                     					  ->setBaseSubtotal($ordersubtotal)
                                     					  ->setTaxAmount($ordertaxAmount)
                                     					  ->setBaseTaxAmount($ordertaxAmount)
                                     					  ->setGrandTotal($ordergrandtotal)
                                     					  ->setBaseGrandTotal($ordergrandtotal);
                                     				$order->save();
                                     				if ($order->hasInvoices()) {
                                     				$invIncrementIDs = array();
                                     				foreach ($order->getInvoiceCollection() as $inv) {
                                     					$invIncrementIDs[] = $inv->getIncrementId();
                                     				}
                                     
                                     				$invoice = Mage::getModel("sales/order_invoice")->loadByIncrementId($invIncrementIDs[0]);
                                     				$invoice->setTotalQty($chordertotalqty)
                                     							->setSubtotal($ordersubtotal)
                                     							->setBaseSubtotal($ordersubtotal)
                                     							->setTaxAmount($ordertaxAmount)
                                     							->setBaseTaxAmount($ordertaxAmount)
                                     							->setGrandTotal($ordergrandtotal)
                                     							->setBaseGrandTotal($ordergrandtotal);
                                     				$invoice->save();
                                     				$logger->info($orderCode."-invoice-update-Success");
                                     				}
                                     				$logger->info($orderCode."-Items-Updated");
                                     			}			
                                     */
                                 }
                                 $order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                                 if (!$order->hasInvoices()) {
                                     $invoice = $order->prepareInvoice();
                                     $invoice->register();
                                     Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder())->save();
                                     $logger->info($orderCode . "-invoice-update-Success");
                                 }
                             }
                             if (strtolower($orderState) != $mageState) {
                                 $order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                                 if ($mageState == 'complete' && !$order->hasInvoices()) {
                                     $invoice = $order->prepareInvoice();
                                     $invoice->register();
                                     Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder())->save();
                                 }
                                 $comment = 'Changing status to ' . $mageStatus . ' Status from unicom';
                                 $isCustomerNotified = false;
                                 $order->setState($mageState, $mageStatus, $comment, $isCustomerNotified);
                                 $order->save();
                                 //Mage::log($orderCode."-Success",null,'orderstatus.log');
                                 $logger->info($orderCode . "-Success");
                             }
                         }
                     } else {
                         $getSearchOrder = $myPackageServiceSearch->getLastError();
                         //Mage::log($orderCode."-error",null,'orderstatus.log');
                         $logger->info($orderCode . "-error");
                     }
                 }
             } else {
                 //Mage::log($orderCode."-error",null,'orderstatus.log');
                 $logger->info($orderCode . "-error");
             }
         } else {
             $orderresponse = $myPackageServiceGet->getLastError();
             //Mage::log($orderCode."-error",null,'orderstatus.log');
             $logger->info($orderCode . "-error");
         }
     }
 }
コード例 #3
0
 public function unicomOrderItemUpdate(Varien_Event_Observer $observer)
 {
     $orderlog = Mage::getBaseDir() . '/var/order/unicomupdate.log';
     $writer = new Zend_Log_Writer_Stream($orderlog);
     $logger = new Zend_Log($writer);
     $wsdlUrl = Mage::getStoreConfig('unicom_options/unigroup/uniurl');
     $wsdllUrl = Mage::getStoreConfig('unicom_options/unigroup/unilurl');
     $uniUname = Mage::getStoreConfig('unicom_options/unigroup/uniusername');
     $uniPass = Mage::getStoreConfig('unicom_options/unigroup/unipass');
     define('MYPACKAGE_WSDL_URL', $wsdlUrl);
     define('MYPACKAGE_WSDL_LURL', $wsdllUrl);
     define('MYPACKAGE_USER_LOGIN', $uniUname);
     define('MYPACKAGE_USER_PASSWORD', $uniPass);
     $wsdl = array();
     $wsdl[MyPackageWsdlClass::WSDL_URL] = MYPACKAGE_WSDL_URL;
     $wsdl[MyPackageWsdlClass::WSDL_LURL] = MYPACKAGE_WSDL_LURL;
     $wsdl[MyPackageWsdlClass::WSDL_CACHE_WSDL] = WSDL_CACHE_NONE;
     $wsdl[MyPackageWsdlClass::WSDL_TRACE] = true;
     if (MYPACKAGE_USER_LOGIN !== '') {
         $wsdl[MyPackageWsdlClass::WSDL_LOGIN] = MYPACKAGE_USER_LOGIN;
     }
     if (MYPACKAGE_USER_PASSWORD !== '') {
         $wsdl[MyPackageWsdlClass::WSDL_PASSWD] = MYPACKAGE_USER_PASSWORD;
     }
     $resource = Mage::getSingleton('core/resource');
     $readConnection = $resource->getConnection('core_read');
     $query = 'SELECT * FROM ' . $resource->getTableName('sales/order') . ' WHERE status NOT IN ("complete","canceled","pending")';
     $orders = $readConnection->fetchAll($query);
     $orderId = array();
     foreach ($orders as $order) {
         $orderCode = $order['increment_id'];
         $orderState = $order['status'];
         $order['Code'] = $orderCode;
         $myPackageServiceGet = new MyPackageServiceGet($wsdl);
         $orderresponse = array();
         $unicom_skus = array();
         if ($myPackageServiceGet->GetSaleOrder(new MyPackageStructGetSaleOrderRequest($order))) {
             $orderresponse = $myPackageServiceGet->getResult();
             $sucessresponse = $orderresponse->Successful;
             $getorder = new MyPackageStructGetSaleOrderResponse($sucessresponse->Successful, $sucessresponse->Errors, $sucessresponse->Warnings, $sucessresponse->SaleOrder);
             if ($getorder->getSuccessful()) {
                 if (count($getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem) > 0) {
                     foreach ($getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem as $item) {
                         if ($item->StatusCode !== "CANCELLED") {
                             $unicom_skus[] = $item->ItemSKU;
                         }
                     }
                 }
                 //$unicom_skus = array('RE110143C','RE110143C');
                 $unicom_cntsku = array_count_values($unicom_skus);
                 $mage_skus = array();
                 $reRowTotal = 0;
                 $order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                 foreach ($order->getAllItems() as $item) {
                     $itemSku = $item->getSku();
                     if (in_array($itemSku, $unicom_skus)) {
                         $mage_skus[] = $itemSku;
                         if ($item->getSku() == $itemSku) {
                             $uqty = $unicom_cntsku[$itemSku];
                             $itemoqty = (int) $item->getQtyOrdered();
                             if ($uqty != $itemoqty) {
                                 $taxPercent = $item->getTaxPercent();
                                 //$itemta = $item->getTaxAmount()/$itemoqty;
                                 $itemreqty = $itemoqty - $uqty;
                                 $originalPrice = $item->getOriginalPrice();
                                 $price = $item->getPrice();
                                 $rowTotal = round($originalPrice * $uqty, 2);
                                 $taxAmount = round($price * $taxPercent / 100 * $uqty, 2);
                                 $subTotal = round($rowTotal - $taxAmount, 2);
                                 $rowTotalInclTax = $subTotal + $taxAmount;
                                 $reOriginalPrice = +($originalPrice * $itemreqty);
                                 $rePrice = +($price * $itemreqty);
                                 $reTaxAmount = +($reOriginalPrice - $rePrice);
                                 $itemorqty = +$itemreqty;
                                 $item->setQtyOrdered($uqty);
                                 $item->setTaxAmount($taxAmount);
                                 $item->setBaseTaxAmount($taxAmount);
                                 $item->setRowTotal($subTotal);
                                 $item->setBaseRowTotal($subTotal);
                                 $item->setRowTotalInclTax($rowTotalInclTax);
                                 $item->setBaseRowTotalInclTax($rowTotalInclTax);
                                 $item->save();
                             }
                         }
                     }
                 }
                 //echo $order->getSubtotal();
                 $osubTotal = $order->getSubtotal() - $rePrice;
                 $otaxAmount = $order->getTaxAmount() - $reTaxAmount;
                 $ograndTotal = $order->getGrandTotal() - $reOriginalPrice;
                 $ototalqty = $order->getTotalQtyOrdered() - $itemorqty;
                 $osubTotalIncltax = $osubTotal + $otaxAmount;
                 //echo $rePrice;
                 $order->setSubtotal($osubTotal);
                 $order->setTaxAmount($otaxAmount);
                 $order->setGrandTotal($ograndTotal);
                 $order->setSubtotalInclTax($osubTotalIncltax);
                 $order->setBaseSubtotal($osubTotal);
                 $order->setBaseTaxAmount($otaxAmount);
                 $order->setBaseGrandTotal($ograndTotal);
                 $order->setBaseSubtotalInclTax($osubTotalIncltax);
                 $order->setTotalQtyOrdered($ototalqty);
                 $order->save();
                 $logger->info($orderCode . "-Success");
             }
         }
     }
 }
コード例 #4
0
 public function ecomOrderStatus(Varien_Event_Observer $observer)
 {
     $orderlog = Mage::getBaseDir() . '/var/order/unicomstatus.log';
     $writer = new Zend_Log_Writer_Stream($orderlog);
     $logger = new Zend_Log($writer);
     $wsdlUrl = Mage::getStoreConfig('unicom_options/unigroup/uniurl');
     $wsdllUrl = Mage::getStoreConfig('unicom_options/unigroup/unilurl');
     $uniUname = Mage::getStoreConfig('unicom_options/unigroup/uniusername');
     $uniPass = Mage::getStoreConfig('unicom_options/unigroup/unipass');
     /*define('MYPACKAGE_WSDL_URL','https://demo.unicommerce.com/services/soap/uniware13.wsdl');
     		define('MYPACKAGE_USER_LOGIN','zoffio');
     		define('MYPACKAGE_USER_PASSWORD','zoff@uni1'); */
     define('MYPACKAGE_WSDL_URL', $wsdlUrl);
     define('MYPACKAGE_WSDL_LURL', $wsdllUrl);
     define('MYPACKAGE_USER_LOGIN', $uniUname);
     define('MYPACKAGE_USER_PASSWORD', $uniPass);
     $wsdl = array();
     $wsdl[MyPackageWsdlClass::WSDL_URL] = MYPACKAGE_WSDL_URL;
     $wsdl[MyPackageWsdlClass::WSDL_LURL] = MYPACKAGE_WSDL_LURL;
     $wsdl[MyPackageWsdlClass::WSDL_CACHE_WSDL] = WSDL_CACHE_NONE;
     $wsdl[MyPackageWsdlClass::WSDL_TRACE] = true;
     if (MYPACKAGE_USER_LOGIN !== '') {
         $wsdl[MyPackageWsdlClass::WSDL_LOGIN] = MYPACKAGE_USER_LOGIN;
     }
     if (MYPACKAGE_USER_PASSWORD !== '') {
         $wsdl[MyPackageWsdlClass::WSDL_PASSWD] = MYPACKAGE_USER_PASSWORD;
     }
     $resource = Mage::getSingleton('core/resource');
     $readConnection = $resource->getConnection('core_read');
     $query = 'SELECT * FROM ' . $resource->getTableName('sales/order') . ' WHERE status NOT IN ("complete","canceled")';
     $orders = $readConnection->fetchAll($query);
     $orderId = array();
     foreach ($orders as $order) {
         $orderCode = $order['increment_id'];
         $orderState = $order['status'];
         $order['Code'] = $orderCode;
         $myPackageServiceGet = new MyPackageServiceGet($wsdl);
         $orderresponse = array();
         if ($myPackageServiceGet->GetSaleOrder(new MyPackageStructGetSaleOrderRequest($order))) {
             $orderresponse = $myPackageServiceGet->getResult();
             $sucessresponse = $orderresponse->Successful;
             $getorder = new MyPackageStructGetSaleOrderResponse($sucessresponse->Successful, $sucessresponse->Errors, $sucessresponse->Warnings, $sucessresponse->SaleOrder);
             if ($getorder->getSuccessful()) {
                 $checkItemStatus = true;
                 $statusCode = "";
                 if (count($getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem) > 0) {
                     foreach ($getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem as $item) {
                         if ($statusCode !== "") {
                             if ($statusCode != $item->StatusCode) {
                                 $checkItemStatus = false;
                             }
                         }
                         $statusCode = $item->StatusCode;
                     }
                 } else {
                     $statusCode = $getorder->getSaleOrder()->SaleOrderItems->SaleOrderItem->StatusCode;
                 }
                 if ($checkItemStatus == true) {
                     if ($statusCode == "CREATED") {
                         $mageState = 'approved';
                         $mageStatus = 'Approved';
                     } elseif ($statusCode == "FULFILLABLE" || $statusCode == "UNFULFILLABLE") {
                         $mageState = 'processing';
                         $mageStatus = 'Processing';
                     } elseif ($statusCode == "CANCELLED") {
                         $mageState = 'canceled';
                         $mageStatus = 'Canceled';
                     } elseif ($statusCode == "DISPATCHED") {
                         $mageState = 'shipped';
                         $mageStatus = 'Shipped';
                     } elseif ($statusCode == "DELIVERED") {
                         $mageState = 'complete';
                         $mageStatus = 'Complete';
                     } else {
                         $mageState = 'processing';
                         $mageStatus = 'Processing';
                     }
                     //Mage::log($orderCode."-Success",null,'orderstatus.log');
                     //$orderId = '141433271';
                     if (strtolower($orderState) != $mageState) {
                         $order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                         $comment = 'Changing status to ' . $mageStatus . ' Status from unicom';
                         $isCustomerNotified = false;
                         $order->setState($mageState, $mageStatus, $comment, $isCustomerNotified);
                         $order->save();
                         //Mage::log($orderCode."-Success",null,'orderstatus.log');
                         $logger->info($orderCode . "-Success");
                     }
                 } else {
                     $myPackageServiceSearch = new MyPackageServiceSearch($wsdl);
                     if ($myPackageServiceSearch->SearchSaleOrder(new MyPackageStructSearchSaleOrderRequest($orderCode, NULL, NULL, NULL, NULL, NULL, NULL, new MyPackageStructSearchOptions(0)))) {
                         $getSearchOrder = $myPackageServiceSearch->getResult();
                         $statusCode = $getSearchOrder->Successful->SaleOrders->SaleOrder->Status;
                         if ($statusCode == "CREATED") {
                             $mageState = 'approved';
                             $mageStatus = 'Approved';
                         } elseif ($statusCode == "PROCESSING") {
                             $mageState = 'processing';
                             $mageStatus = 'Processing';
                         } elseif ($statusCode == "CANCELLED") {
                             $mageState = 'canceled';
                             $mageStatus = 'Canceled';
                         } elseif ($statusCode == "COMPLETE") {
                             $mageState = 'complete';
                             $mageStatus = 'Complete';
                         } else {
                             $mageState = 'processing';
                             $mageStatus = 'Processing';
                         }
                         if (strtolower($orderState) != $mageState) {
                             $order = Mage::getModel('sales/order')->loadByIncrementId($orderCode);
                             $comment = 'Changing status to ' . $mageStatus . ' Status from unicom';
                             $isCustomerNotified = false;
                             $order->setState($mageState, $mageStatus, $comment, $isCustomerNotified);
                             $order->save();
                             //Mage::log($orderCode."-Success",null,'orderstatus.log');
                             $logger->info($orderCode . "-Success");
                         }
                     } else {
                         $getSearchOrder = $myPackageServiceSearch->getLastError();
                         //Mage::log($orderCode."-error",null,'orderstatus.log');
                         $logger->info($orderCode . "-error");
                     }
                 }
             } else {
                 //Mage::log($orderCode."-error",null,'orderstatus.log');
                 $logger->info($orderCode . "-error");
             }
         } else {
             $orderresponse = $myPackageServiceGet->getLastError();
             //Mage::log($orderCode."-error",null,'orderstatus.log');
             $logger->info($orderCode . "-error");
         }
     }
 }