Example #1
0
 /**
  * @return bool
  */
 public function logout()
 {
     if (null !== $this->sessionId) {
         $this->soapClient->endSession($this->sessionId);
         $this->sessionId = null;
         return true;
     }
     return false;
 }
Example #2
0
<?php

$client = new SoapClient('http://184.73.176.25/magento/index.php/api/?wsdl', array("trace" => 1));
// If soap isn't default use this link instead
// http://youmagentohost/api/soap/?wsdl
// If somestuff requires api authentification,
// we should get session token
$session = $client->login('needle', '123456');
// $id = $client->call($session, 'coupongenerator.clonerule', array('2', '__NDL_RULE', 'NEEDLE7'));
$result = $client->call($session, 'coupongenerator.info', 2);
print_r($result);
// $result = $client->call($session, 'coupongenerator.delete', $id);
// If you don't need the session anymore
$client->endSession($session);
 public function mamethodeAction()
 {
     echo "<pre>";
     $baseDir = Mage::getBaseDir('code');
     // include_once
     // $baseDir.'app/code/community/IWD/OrderManager/Model/Order/Edit.php';
     // echo $baseDir.'<br>';
     // Mage::log($baseDir,null, 'wms-api.log');
     // echo $this->apiUrl. " == " .$this->apiUser. " == "
     // .$this->apiPassword;
     $date = date('Y-m-d h:i:s');
     echo "Date is " . $date . "<br>";
     /**
      * #####################################################################################
      */
     // Establish the connection to WMS api
     $proxy = new SoapClient($this->apiUrl);
     $sessionId = $proxy->login($this->apiUser, $this->apiPassword);
     echo $sessionId;
     // $order_increment_Id = "151020C-811018";
     // $order_increment_Id = "20151019C-1992393";
     /*
      * ComplexFilter For Order filter
      */
     $complexFilterOrder = array('complex_filter' => array(array('key' => 'updated_at', 'value' => array('key' => 'from', 'value' => date('Y-m-d', strtotime("-6 days")) . " 00:00:00")), array('key' => 'updated_at', 'value' => array('key' => 'to', 'value' => date('Y-m-d') . " 00:02:00"))));
     /*
      * Get Updated Order list from the WMS 
      */
     $order_list = $proxy->salesOrderList($sessionId, $complexFilterOrder);
     $count = 1;
     /*
      * Loop through each Order from WMS to check for Invoices and Shipment
      */
     foreach ($order_list as $order) {
         echo "<br>Order : " . $count . "<br>";
         $count++;
         /*
          * Complex filter to filter out new Invoices and Shipment for the Corresponding OrderId Instead of the increment order ID
          */
         $complexFilter = array('complex_filter' => array(array('key' => 'order_id', 'value' => array('key' => 'in', 'value' => $order->order_id)), array('key' => 'created_at', 'value' => array('key' => 'from', 'value' => date('Y-m-d', strtotime("-6 days")) . " 00:00:00")), array('key' => 'created_at', 'value' => array('key' => 'to', 'value' => date('Y-m-d') . " 00:02:00"))));
         // echo "<br>##########################################<br>";
         echo "---------------" . $order->order_id . "---------------<br>";
         // echo "<br><br>";
         /*
          * Invoice list for the order.
          */
         $invoice_list = $proxy->salesOrderInvoiceList($sessionId, $complexFilter);
         /*
          * shipment list for the order.
          */
         $shipment_list = $proxy->salesOrderShipmentList($sessionId, $complexFilter);
         /*
          * If there is no invoice or shipment continu with next Order
          */
         if (count($invoice_list) < 1 && count($shipment_list) < 1) {
             echo "NO Invoice and Shipment<br>";
             continue;
         }
         var_dump($invoice_list);
         var_dump($shipment_list);
         echo "<br>##########################################<br>";
         /*
          * $invoice_list =
          * $proxy->salesOrderInvoiceList($sessionId,$complexFilter);
          * $shipment_list =
          * $proxy->salesOrderShipmentList($sessionId,$complexFilter);
          * var_dump($invoice_list);
          * var_dump($shipment_list);
          */
         /*
          * For each invoice in the invoice list
          */
         foreach ($invoice_list as $invoice) {
             $invoice_info = $proxy->salesOrderInvoiceInfo($sessionId, $invoice->increment_id);
             // var_dump($invoice_info);
             //var_dump(get_class($invoice_info));
             $this->addInvoiceFromWMS($invoice_info, $order->order_id);
         }
         /*
          * foreach shipment in the shipment list
          */
         foreach ($shipment_list as $shipment) {
             $shipment_info = $proxy->salesOrderShipmentInfo($sessionId, $shipment->increment_id);
             //var_dump(get_class($shipment_info));
             // var_dump($shipping_info->order_increment_id);
             $this->addShipmentFromWMS($shipment_info, $order->order_id);
         }
     }
     $proxy->endSession($sessionId);
     echo "</pre>";
 }
Example #4
0
 public function Processshopupdatepwd($mageid, $newpswd)
 {
     $client = new SoapClient('http://' . $_SERVER['SERVER_NAME'] . '/shop/api/soap/?wsdl');
     $sessionId = $client->login('apiintegrator', 'ap11ntegrator');
     $result = $client->call($sessionId, 'customer.update', array('customerId' => $mageid, 'customerData' => array('password_hash' => $newpswd)));
     /* if($result)
        
        echo $mageid.' '.$rawpass.'success';*/
     $client->endSession($sessionId);
 }
Example #5
0
 /**
  * Product create or update in WMS
  *
  * @param int $pid            
  * @return Zoffio_WmsApi_Model_Observer
  */
 public function productCreateOrUpdateWMS(int $pid)
 {
     // load Product using the Id
     $product = Mage::getModel('catalog/product')->load($pid);
     $product_type = $product->getData('type_id');
     // Do call api only if the added product is simple
     if ($product_type === 'simple') {
         // Establish the connection to WMS api
         $proxy = new SoapClient(self::$_apiUrl);
         $sessionId = $proxy->login(self::$_apiUser, self::$_apiPassword);
         // Product details
         $product_sku = $product->getData('sku');
         $product_categories = $product->getCategoryIds();
         $product_name = $product->getData('name');
         $product_description = $product->getData('description');
         $product_short_description = $product->getData('short_description');
         $product_price = $product->getData('price');
         $product_weight = $product->getData('weight');
         $product_status = $product->getData('status');
         $product_url_key = $product->getData('url_key');
         $product_url_path = $product->getData('url_path');
         $product_visibility = $product->getData('visibility');
         $product_meta_title = $product->getData('meta_title');
         $product_meta_keyword = $product->getData('meta_keyword');
         $product_meta_description = $product->getData('meta_description');
         // Load product inventory
         $product_inventory = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
         // Mage::log($product_inventory->getData(), null, 'shebin.log');
         // Load product Inverntry details
         $product_qty = $product_inventory->getData('qty');
         $product_is_in_stock = $product_inventory->getData('is_in_stock');
         $product_manage_stock = $product_inventory->getData('manage_stock');
         $product_use_config_manage_stock = $product_inventory->getData('use_config_manage_stock');
         // Get product image
         $product_image = $product->getImage();
         // Load Product Main Image details if Product image exists
         if ($product_image != "no_selection" && $product_image != null) {
             $product_image_url = Mage::getModel('catalog/product_media_config')->getMediaUrl($product_image);
             // get the contents of the image file from the Url
             $product_image_content = file_get_contents($product_image_url);
             $product_image_name = pathinfo($product_image_url, PATHINFO_FILENAME);
             /* get image mime type */
             $file_info = new finfo(FILEINFO_MIME);
             // object oriented
             // approach!
             $product_image_mime_type = substr($file_info->buffer($product_image_content), 0, strpos($file_info->buffer($product_image_content), ';'));
             // File Object to be send via the API
             $product_image_file = array('name' => $product_image_name, 'content' => base64_encode($product_image_content), 'mime' => $product_image_mime_type);
             // Image deails to be added or created at WMS
             $product_image_details = array('file' => $product_image_file, 'types' => array('thumbnail', 'small_image', 'image'), 'exclude' => 0);
         }
         // Product details to be sent to WMS
         $product_details = array('categories' => $product_categories, 'websites' => array(1), 'name' => $product_name, 'description' => $product_description, 'short_description' => $product_short_description, 'price' => $product_price, 'weight' => $product_weight, 'status' => $product_status, 'url_key' => $product_url_key, 'url_path' => $product_url_path, 'visibility' => $product_visibility, 'tax_class_id' => $product_tax_class_id, 'meta_title' => $product_meta_title, 'meta_keyword' => $product_meta_keyword, 'meta_description' => $product_description, 'stock_data' => array('qty' => $product_qty, 'is_in_stock' => $product_is_in_stock, 'manage_stock' => $product_manage_stock, 'use_config_manage_stock' => $product_use_config_manage_stock));
         // Get attribute set
         $attributeSets = $proxy->catalogProductAttributeSetList($sessionId);
         $attributeSet = current($attributeSets);
         // TODO removal of product image
         // Fetch product details using the SKU from WMS
         try {
             $wms_product_exist = $proxy->catalogProductInfo($sessionId, $product_sku);
             // Mage::log($wms_product_exist, null, 'shebin.log');
         } catch (Exception $e) {
             Mage::log("WMS: No such products!", 1, 'wms-api.log');
         }
         // If Product not exists in WMS then create
         if ($wms_product_exist == null || $wms_product_exist == "") {
             try {
                 $result = $proxy->catalogProductCreate($sessionId, $product_type, $attributeSet->set_id, $product_sku, $product_details);
                 // set the product WMS ID.
                 Mage::log($result, null, 'wms-api.log');
                 $product->setData('wms_pid', $result);
                 $product->getResource()->saveAttribute($product, 'wms_pid');
                 // Mage::log("CreateProduct:", null, 'shebin.log');
                 // Mage::log($result, null, 'shebin.log');
             } catch (Exception $e) {
                 Mage::log($e->getMessage(), 3, 'wms-api.log');
                 Mage::log($e->getTraceAsString(), 3, 'wms-api.log');
                 Mage::log($product_details, null, 'wms-api.log');
             }
             // Product image add to WMS
             if ($product_image != "no_selection" && $product_image != null) {
                 try {
                     $result = $proxy->catalogProductAttributeMediaCreate($sessionId, $product_sku, $product_image_details);
                     // Mage::log($result." :Image Create on Update", null,
                     // 'shebin.log');
                 } catch (Exception $e) {
                     Mage::log($e->getMessage() . 'Create fail', 3, 'wms-api.log');
                     Mage::log($product_image_details, null, 'wms-api.log');
                 }
             }
         } else {
             // else Update the existing product
             try {
                 $result = $proxy->catalogProductUpdate($sessionId, $product_sku, $product_details);
                 // Mage::log("UpdateProduct:", null, 'shebin.log');
                 // Mage::log($result, null, 'shebin.log');
             } catch (Exception $e) {
                 Mage::log($e->getMessage(), 3, 'wms-api.log');
                 Mage::log($product_details, null, 'wms-api.log');
             }
             // if product image does not Exists create product image else
             // update
             if ($product_image != "no_selection" && $product_image != null) {
                 try {
                     // check exixstence of the product image
                     $result2 = $proxy->catalogProductAttributeMediaInfo($sessionId, $product_sku, $product_image);
                     // Mage::log($result2 , null, 'wms-api.log');
                 } catch (Exception $e) {
                     Mage::log($e->getMessage() . " WMS: No products image!", 1, 'wms-api.log');
                     // Mage::log($proxy->catalogProductAttributeMediaList(
                     // $sessionId, $product_sku), 1, 'wms-api.log');
                 }
                 // Check product image Exist or not
                 if ($result2 == null || ($result2 = "")) {
                     try {
                         $result = $proxy->catalogProductAttributeMediaCreate($sessionId, $product_sku, $product_image_details);
                         // Mage::log($result." :Image Create on Update",
                         // null,
                         // 'shebin.log');
                     } catch (Exception $e) {
                         Mage::log($e->getMessage() . 'Create fail', 3, 'wms-api.log');
                         Mage::log($product_image_details, null, 'wms-api.log');
                     }
                 } else {
                     // Product image Update
                     try {
                         $result = $proxy->catalogProductAttributeMediaUpdate($sessionId, $product_sku, $product_image, $product_image_details);
                         // Mage::log($result."Image update on Update", null,
                         // 'shebin.log');
                     } catch (Exception $e) {
                         Mage::log($e->getMessage() . " Update fail", 3, 'wms-api.log');
                         Mage::log($product_image_details, null, 'wms-api.log');
                     }
                 }
             }
         }
     } else {
         Mage::log($product_type . " products will not be added to WMS!", 5, 'wms-api.log');
         return $this;
     }
     $proxy->endSession($sessionId);
     // closing session
     return $this;
 }