<?php $proxy = new SoapClient('http://127.0.0.1/magento/index.php/api/v2_soap/?wsdl'); $sessionId = $proxy->login('cats', 'sudhir123'); echo "\nSession Id = "; var_dump($sessionId); $cartId = $proxy->shoppingCartCreate($sessionId, '3'); echo "\nCart Id = "; var_dump($cartId); $customerData = array("firstname" => "testFirstname", "lastname" => "testLastName", "email" => "*****@*****.**", "mode" => "guest", "website_id" => "0"); $resultCustomerSet = $proxy->shoppingCartCustomerSet($sessionId, $cartId, $customerData); echo "\nCustomer Set to Shopping Cart = "; var_dump($resultCustomerSet); $customeraddress = $proxy->shoppingCartCustomerAddresses($sessionId, $cartId, array(array('mode' => 'billing', 'firstname' => 'Sudhir', 'lastname' => 'Belagali', 'street' => 'sanmati marg', 'city' => 'dharwad', 'region' => 'dharwad', 'postcode' => '580001', 'country_id' => 'India', 'telephone' => '9538647544', 'is_default_billing' => 1))); echo "\nCustomer Address Set to Shopping Cart = "; var_dump($customeraddress); $shoppingcartproduct = $proxy->shoppingCartProductAdd($sessionId, $cartId, array(array('product_id' => '917', 'sku' => 'cricketbat', 'qty' => '5', 'options' => null, 'bundle_option' => null, 'bundle_option_qty' => null, 'links' => null))); echo "\nProduct has been added to cart = "; var_dump($shoppingcartproduct); //$cartInfo = $proxy->shoppingCartInfo($sessionId, $cartId); //echo "\nCart Information for this Cart Id is ( ".$cartId." )"; //var_dump($cartInfo); // get list of shipping methods $resultShippingMethods = $proxy->shoppingCartShippingList($sessionId, $cartId); echo "\nAvailable shipping methods = \n"; var_dump($resultShippingMethods); // set shipping method $randShippingMethodIndex = rand(0, count($resultShippingMethods) - 1); //$shippingMethod = $resultShippingMethods[$randShippingMethodIndex]["code"]; $resultShippingMethod = $proxy->shoppingCartShippingMethod($sessionId, $cartId, "freeshipping_freeshipping"); echo "\nFinal result\n";
/** * Function to add or update Approved Order to the WMS. * * @param Varien_Event_Observer $observer * @return void|Zoffio_WmsApi_Model_Observer */ public function orderSaveAfter(Varien_Event_Observer $observer) { Mage::log(__CLASS__ . "_" . __FUNCTION__ . " " . self::$_observerExecutionCounter, null, 'shebin.log'); /* * Avoid multiple execution */ if (self::$_observerExecutionCounter > 1) { return $this; } $order = $observer->getEvent()->getOrder(); Mage::log($order->getData('status'), null, 'shebin.log'); $order_status = $order->getData('status'); // Check that the Orde status is set or not // Issue fix event triggerd multiple times during the place order after if (!isset($order_status) || trim($order_status) === '') { return $this; } else { if (trim($order_status) === 'approved' || trim($order_status) === 'canceled') { self::$_observerExecutionCounter++; } } // Do not push Order that are not approved. if ($order_status != 'approved' && $order_status != 'canceled') { Mage::log('Order not pushed in WMS. Status: ' . $order_status, null, 'wms-api.log', true); return $this; } // Get increment Order Id $zoffio_order_id = $order->getIncrementId(); $order_customer_id = $order->getCustomerId(); $zoff_domain = 'zoffio.com'; // custom email genrated for zoffio wms api Registration $wms_email_id = $order_customer_id . "@" . $zoff_domain; Mage::log($wms_email_id, null, 'shebin.log'); $complexFilter = array('complex_filter' => array(array('key' => 'email', 'value' => array('key' => 'eq', 'value' => $wms_email_id)))); // Complex filter for geting order list from increment ID $order_complexFilter = array('complex_filter' => array(array('key' => 'increment_id', 'value' => array('key' => 'eq', 'value' => $zoffio_order_id)))); // connect to the WMS API $proxy = new SoapClient(self::$_apiUrl); $sessionId = $proxy->login(self::$_apiUser, self::$_apiPassword); // Check Order existence in WMS try { $order_existWms = $proxy->salesOrderList($sessionId, $order_complexFilter); } catch (Exception $e) { Mage::log($e->getMessage(), null, 'wms-api.log'); Mage::log($e->getTraceAsString(), null, 'wms-api.log'); } // Do not push the cancell orders that was not approved to WMS if ($order_status == 'canceled' && count($order_existWms) < 1) { /* * Order should not be pushed when the cancelled order is not there * in the WMS. ie., the Order was not approved. */ Mage::log('Order canceled which is not in WMS ' . $zoffio_order_id, null, 'wms-api.log', true); return $this; } // Mage::log($billing_address, null, 'shebin.log'); $order_shipping_address = $order->getShippingAddress(); $order_billing_address = $order->getBillingAddress(); $shipping_address = array('mode' => $order_shipping_address->getData('address_type'), 'firstname' => $order_shipping_address->getData('firstname'), 'lastname' => $order_shipping_address->getData('lastname'), 'street' => $order_shipping_address->getData('street'), 'city' => $order_shipping_address->getData('city'), 'region' => $order_shipping_address->getData('region'), 'telephone' => $order_shipping_address->getData('telephone'), 'postcode' => $order_shipping_address->getData('postcode'), 'country_id' => $order_shipping_address->getData('country_id'), 'is_default_shipping' => 0, 'is_default_billing' => 0); $billing_address = array('mode' => $order_billing_address->getData('address_type'), 'firstname' => $order_billing_address->getData('firstname'), 'lastname' => $order_billing_address->getData('lastname'), 'street' => $order_billing_address->getData('street'), 'city' => $order_billing_address->getData('city'), 'region' => $order_billing_address->getData('region'), 'telephone' => $order_billing_address->getData('telephone'), 'postcode' => $order_billing_address->getData('postcode'), 'country_id' => $order_billing_address->getData('country_id'), 'is_default_shipping' => 0, 'is_default_billing' => 0); // Mage::log($shipping_address, null, 'shebin.log'); $order_address = array($shipping_address, $billing_address); // Mage::log(var_dump($order_address, TRUE), null, 'shebin.log'); $order_shipping_method = $order->getShippingMethod(); // free shipping above 499 only if ($order->getData('base_subtotal_incl_tax') < 500) { $order_shipping_method = 'flatrate_flatrate'; } else { // $order_shipping_method = $order->getShippingMethod(); $order_shipping_method = 'freeshipping_freeshipping'; } $order_payment_method = $order->getPayment()->getMethodInstance()->getCode(); $paymentMethod = array('method' => $order_payment_method); // Create Order If No order in WMS with same Increment ID. if (count($order_existWms) < 1) { // Creating the order products array to be passed to WMS create if ($order->getId()) { $order_products = array(); $order_items = $order->getAllVisibleItems(); foreach ($order_items as $item) { $item_sku = $item->getSku(); $item_qty = $item->getQtyOrdered(); $item_subtotal_incl_tax = $item->getBaseRowTotal() + $item->getTaxAmount(); $item_price = $item_subtotal_incl_tax / (double) $item_qty; $item_discount = $item->getDiscount(); $order_products[] = array('sku' => $item_sku, 'quantity' => $item_qty, 'erp_price' => $item_price, 'erp_discount' => $item_discount); } } Mage::log($order_products, null, 'shebin.log'); Mage::log("Create order", null, 'shebin.log'); // create Order try { // Set cart ID $cartId = $proxy->shoppingCartCreate($sessionId, 1); // Load the customer list and select the first customer from WMS $customerList = $proxy->customerCustomerList($sessionId, $complexFilter); // Get customer Object $wms_cust_obj = $customerList[0]; $wms_customer = array(); $wms_customer['customer_id'] = $wms_cust_obj->customer_id; $wms_customer['email'] = $wms_cust_obj->email; $wms_customer['firstname'] = $wms_cust_obj->firstname; $wms_customer['lastname'] = $wms_cust_obj->lastname; $wms_customer['mode'] = 'customer'; Mage::log($wms_customer, null, 'shebin.log'); // return $this; // Set shopping cart customer for which the order is being // created $proxy->shoppingCartCustomerSet($sessionId, $cartId, $wms_customer); // Add products to the cart $proxy->shoppingCartProductAdd($sessionId, $cartId, $order_products); // add customer address Shipping and Billing $proxy->shoppingCartCustomerAddresses($sessionId, $cartId, $order_address); // add shipping method $proxy->shoppingCartShippingMethod($sessionId, $cartId, $order_shipping_method); // add payment method $proxy->shoppingCartPaymentMethod($sessionId, $cartId, $paymentMethod); // place the order (Extended api) $orderId = $proxy->shoppingCartOrder($sessionId, $cartId, null, null, $zoffio_order_id); Mage::log($orderId, null, 'shebin.log'); } catch (Exception $e) { Mage::log($e->getMessage(), null, 'shebin.log'); Mage::log($e->getTraceAsString(), null, 'shebin.log'); Mage::log($e->getLine(), null, 'shebin.log'); // Mage::log($wms_customer, null, 'shebin.log'); } return $this; } else { // Order Update if ($order->getId()) { $order_products = array(); $order_items = $order->getAllVisibleItems(); foreach ($order_items as $item) { $item_sku = $item->getSku(); $item_qty = $item->getQtyOrdered(); $item_subtotal_incl_tax = $item->getBaseRowTotal() + $item->getTaxAmount(); $item_price = $item_subtotal_incl_tax / (double) $item_qty; $order_products[] = array('sku' => $item_sku, 'qty' => $item_qty, 'price' => $item_price, 'order_increment_id' => $zoffio_order_id); Mage::log($item->getSubtotal() . " subtotal " . $item_subtotal_incl_tax, null, 'shebin.log'); Mage::log($item_price, null, 'shebin.log'); } } Mage::log($order_products, null, 'shebin.log'); Mage::log("Update order", null, 'shebin.log'); try { $result = $proxy->mdnapiOrderupdateOrderItems($sessionId, $order_products); $result = $proxy->salesOrderAddComment($sessionId, $zoffio_order_id, $order_status); } catch (Exception $e) { Mage::log($e->getMessage(), null, 'shebin.log'); Mage::log($e->getTraceAsString(), null, 'shebin.log'); } // $proxy->endSession($sessionId); return $this; } $proxy->endSession($sessionId); return $this; }
require_once $mageFilename; ini_set('display_errors', 1); ini_set('display_startup_errors', 1); //error_reporting ( - 1 ); error_reporting(1); umask(0); Mage::app("default"); $proxy = new SoapClient('http://52.11.138.2/index.php/api/v2_soap/?wsdl'); $sessionId = $proxy->login('testapi', 'justdoit'); $cartId = $proxy->shoppingCartCreate($sessionId, 1); // load the customer list and select the first customer from the list $complexFilter = array('complex_filter' => array(array('key' => 'email', 'value' => array('key' => 'eq', 'value' => '*****@*****.**')))); $customerList = $proxy->customerCustomerList($sessionId, $complexFilter); $customer = (array) $customerList[0]; $customer['mode'] = 'customer'; $proxy->shoppingCartCustomerSet($sessionId, $cartId, $customer); // load the product list and select the first product from the list $complexFilter = array('complex_filter' => array(array('key' => 'sku', 'value' => array('key' => 'eq', 'value' => 'testMritun2')))); $productList = $proxy->catalogProductList($sessionId, $complexFilter); $product = (array) $productList[0]; $product['qty'] = 1; $product['erp_price'] = 100; $product['erp_discount'] = 12; $proxy->shoppingCartProductAdd($sessionId, $cartId, array($product)); $address = array(array('mode' => 'shipping', 'firstname' => $customer['firstname'], 'lastname' => $customer['lastname'], 'street' => 'Domlur 2nd layout', 'city' => 'Bangalore', 'region' => 'Karnataka', 'telephone' => '9691588020', 'postcode' => '560071', 'country_id' => 'IN', 'is_default_shipping' => 0, 'is_default_billing' => 0), array('mode' => 'billing', 'firstname' => $customer['firstname'], 'lastname' => $customer['lastname'], 'street' => 'Domlur 2nd layout', 'city' => 'Bangalore', 'region' => 'Karnataka', 'telephone' => '9691588020', 'postcode' => '560071', 'country_id' => 'IN', 'is_default_shipping' => 0, 'is_default_billing' => 0)); // add customer address $proxy->shoppingCartCustomerAddresses($sessionId, $cartId, $address); // add shipping method $proxy->shoppingCartShippingMethod($sessionId, $cartId, 'flatrate_flatrate'); $paymentMethod = array('po_number' => null, 'method' => 'checkmo', 'cc_cid' => null, 'cc_owner' => null, 'cc_number' => null, 'cc_type' => null, 'cc_exp_year' => null, 'cc_exp_month' => null); // add payment method