self::ADAPTER_CONVERT_CAPABILITY, 'Creditmemos' => self::ADAPTER_CONVERT_CAPABILITY ); public function shippingLine ( $order, $type = 'Item' ) { $navisionItem = array(); $tax_info = $order->getFullTaxInfo(); $shippingItem = array ( 'Type'=>'Sale', 'Supplier'=>'1', 'Qty'=>1, 'LineAmount'=> (float)$order->getBaseShippingAmount() + (float)$order->getBaseShippingTaxAmount(), 'ItemGroup'=>9904, 'DiscountAmount'=>(float)$order->getBaseShippingDiscountAmount() ); return $shippingItem; } public function shippingLineMemo ( $order, $type = 'Item' ) { $navisionItem = array(); $tax_info = $order->getFullTaxInfo(); $shippingItem = array ( 'Type'=>'Sale', 'ItemGroup'=>'1', 'Supplier'=>'1', 'Qty'=>1, 'LineAmount'=> -((float)$order->getShippingAmount() + (float)$order->getShippingTaxAmount()), 'EDBNumber'=>9904, 'DiscountAmount'=>-(float)$order->getShippingDiscountAmount() ); return $shippingItem; } public function convertOrders ( $order ) { $order = Mage::getModel("sales/order")->load($order->getId()); $ordered_items = $order->getAllItems(); $items_ebd = $itemLines = array(); foreach ( $ordered_items as $item ) { if($item->getProductType() == 'simple') { $_product = Mage::getModel('catalog/product')->load($item->getProductId()); if ( $item->getParentItemId() ) $item_id = $item->getParentItemId(); else $item_id = $item->getId(); $items_ebd[$item_id] = $_product->getEdbNumber(); } } foreach($ordered_items as $item){ $_product = Mage::getModel('catalog/product')->load($item->getProductId()); if($item->getProductType() == 'configurable'){ $ebd_number = $items_ebd[ $item->getId() ]; if ( !$ebd_number ) $ebd_number = '0'; $itemLines[] = array( 'Type'=>'Sale', 'ItemGroup'=>'1', 'Supplier'=>'1', 'Qty'=>$item->getQtyOrdered(), 'LineAmount'=> (float)$item->getPriceInclTax(), 'EDBNumber'=>$ebd_number, 'DiscountAmount'=>(float)($item->getBaseDiscountAmount() / intval($item->getQtyOrdered())), ); $finalQty += $item->getQtyOrdered(); $finalAmount += $item->getPriceInclTax(); } } $shippingItem = $this->shippingLine($order); $itemLines []= $shippingItem; $finalAmount += $shippingItem['LineAmount']; // $paymentMethodCode = $order->getPayment()->getMethodInstance()->getCode(); $paymentLine = array( 'Type'=>'Cash', 'Qty'=> $finalQty, 'LineAmount'=> $finalAmount, ); if ( strlen ( $order->getIncrementId() ) > 8 ) { $order->setIncrementId ( preg_replace("/^(\\d)0/","$1",$order->getIncrementId() ) ); } $saleData = array( 'Type'=>'Sale', 'NoteID'=>str_replace("N", "",$order->getIncrementId()), 'Date'=> date("Y-m-d", strtotime( $order->getCreatedAt() ) ), 'Employee'=>'99', 'Terminal'=>'99', 'ClientNumber'=>Wexo_Integration_Model_Adapter_Custom_CustomDddProducts::DDD_CLIENT_NUMBER, 'psk'=>Wexo_Integration_Model_Adapter_Custom_CustomDddProducts::DDD_CLIENT_KEY, 'ItemLines'=>$itemLines, 'PaymentLines'=>array($paymentLine) ); $dddOrder = array ( 'Web_orderno' => $order->getIncrementId(), 'saleData' => $saleData, ); return array ( $dddOrder ); } public function putOrders( $orders ) { foreach ( $orders as $order ) { // var_dump($order['saleData']); $sClient = new SoapClient('http://api.dddadmin.com/SaleService.svc?wsdl'); $sClient->StartSale($order['saleData']); $response = $sClient->SaveSale(array('sale'=> $order['saleData'], 'psk'=>Wexo_Integration_Model_Adapter_Custom_CustomDddProducts::DDD_CLIENT_KEY)); $this->logEvent("Orders", "Response", "Data is: " . var_export($order, true).", response is: " . var_export($response,true)); if ( !$response->SaveSaleResult->Saved ) { throw new Exception("Could not save order, error: " . $response->SaveSaleResult->Message ); } else { $this->confirmOrders ( array ( $order ) ); } } } public function confirmOrders ( $orders ) { foreach ( $orders as $order ) { $orderId = $order['Web_orderno']; $orderId = preg_replace("/^(\\d)/","\${1}0",$orderId ); echo "writing comment for $orderId\n"; $tmp = array($orderId); $this->_adapterPublisher->confirmOrder ( $tmp ); } } public function convertCreditmemos ( $creditmemo ) { $order = $creditmemo; $ordered_items = $order->getAllItems(); $items_ebd = $order_parents = array(); $_order = Mage::getModel('sales/order')->load ( $creditmemo->getOrderId() ); foreach ( $_order->getAllItems() as $_order_item ) { $order_parents[$_order_item->getId()] = $_order_item->getParentItemId(); } foreach ( $ordered_items as $item ) { $_product = Mage::getModel('catalog/product')->load($item->getProductId()); if($_product->getTypeId() == 'simple') { if ( $order_parents[$item->getOrderItemId()] ) $item_id = $order_parents[$item->getOrderItemId()]; else $item_id = $item->getOrderItemId(); $items_ebd[$item_id] = $_product->getEdbNumber(); } } $finalQty = $finalAmount = 0; Foreach($ordered_items as $item){ $_product = Mage::getModel('catalog/product')->load($item->getProductId()); if($_product->getTypeId() == 'configurable'){ $ebd_number = $items_ebd[ $item->getOrderItemId() ]; if ( !$ebd_number ) $ebd_number = '0'; $itemLines[] = array( 'Type'=>'Sale', 'ItemGroup'=>'1', 'Supplier'=>'1', 'Qty'=>-intval($item->getQty()), 'LineAmount'=> -(float)$item->getPriceInclTax(), 'EDBNumber'=>$ebd_number, 'DiscountAmount'=>(float)($item->getBaseDiscountAmount() / intval($item->getQty())), ); $finalQty -= $item->getQty(); $finalAmount += $item->getPriceInclTax(); } } if ( $order->getShippingAmount() ) { $shippingItem = $this->shippingLineMemo($order); $shippingItem['Qty'] *= -1; } $finalQty -= 1; if ( $shippingItem ) { $itemLines []= $shippingItem; } $finalAmount -= $shippingItem['LineAmount']; // $paymentMethodCode = $order->getPayment()->getMethodInstance()->getCode(); $paymentLine = array( 'Type'=>'Cash', 'Qty'=> $finalQty, 'LineAmount'=> -$finalAmount, ); if ( strlen ( $order->getIncrementId() ) > 8 ) { $order->setIncrementId ( preg_replace("/^(\\d)0/","$1",$order->getIncrementId() ) ); } $saleData = array( 'Type'=>'Sale', 'NoteID'=>str_replace("N", "", $order->getIncrementId()), 'Date'=> date("Y-m-d",strtotime( $order->getCreatedAt() ) ), 'Employee'=>'99', 'Terminal'=>'99', 'ClientNumber'=>Wexo_Integration_Model_Adapter_Custom_CustomDddProducts::DDD_CLIENT_NUMBER, 'psk'=>Wexo_Integration_Model_Adapter_Custom_CustomDddProducts::DDD_CLIENT_KEY, 'ItemLines'=>$itemLines, 'PaymentLines'=>array($paymentLine) ); $dddOrder = array ( 'Web_orderno' => $order->getIncrementId(), 'saleData' => $saleData, ); return array ( $dddOrder ); } public function putCreditmemos( $creditmemos ) { foreach ( $creditmemos as $order ) { $sClient = new SoapClient('http://api.dddadmin.com/SaleService.svc?wsdl'); $sClient->StartSale($order['saleData']); $response = $sClient->SaveSale(array('sale'=> $order['saleData'], 'psk'=> Wexo_Integration_Model_Adapter_Custom_CustomDddProducts::DDD_CLIENT_KEY)); // var_dump ( $response ); $this->logEvent("Creditmemos", "Response", "Data is: " . var_export($order, true).", response is: " . var_export($response,true)); if ( !$response->SaveSaleResult->Saved && $response->SaveSaleResult->Message != "The receipt exists in table batchDataFile" ) { throw new Exception("Could not save order, error: " . $response->SaveSaleResult->Message ); } else { $this->confirmCreditmemos ( array ( $order ) ); } // die('-'); // no exceptions - confirm the order } } public function confirmCreditmemos ( $creditmemos ) { foreach ( $creditmemos as $order ) { $orderId = preg_replace("/^(\\d)0/","$10", $order['Web_orderno'] ); $this->_adapterPublisher->confirmMemo ( $orderId ); } } public function finish() { } }