Ejemplo n.º 1
0
 public function createOrder($cwProductId, $item_qty)
 {
     $preOrdersPerItem = 0;
     $cwProduct = \CodesWholesale\Resource\Product::get($cwProductId);
     $codes = \CodesWholesale\Resource\Order::createBatchOrder($cwProduct, array('quantity' => $item_qty));
     foreach ($codes as $code) {
         if ($code->isPreOrder()) {
             $preOrdersPerItem++;
         }
         $links[] = $code->getHref();
     }
     $createdOrderArray = array('counted_pre_orders' => $preOrdersPerItem, 'links' => $links, 'codes' => $codes);
     return $createdOrderArray;
 }
Ejemplo n.º 2
0
 public function orderProduct($productId, $qty = 1)
 {
     $client = $this->connectToCw();
     $product = $this->getProductById($productId);
     //example
     $url = "https://sandbox.codeswholesale.com/v1/products/ffe2274d-5469-4b0f-b57b-f8d21b09c24c";
     $url = "https://sandbox.codeswholesale.com/v1/products/04aeaf1e-f7b5-4ba9-ba19-91003a04db0a";
     $url = "https://sandbox.codeswholesale.com/v1/products/6313677f-5219-47e4-a067-7401f55c5a3a";
     //$product = \CodesWholesale\Resource\Product::get($url);
     try {
         $codes = \CodesWholesale\Resource\Order::createBatchOrder($product, array('quantity' => $qty));
         return $codes;
     } catch (\CodesWholesale\Resource\ResourceError $e) {
         //Mage::log($e,null,"except.log");
         Mage::helper("kontentaCw")->sentErrorEmail($e, $product, $qty);
         /*if($e->getStatus() == 400 && $e->getErrorCode() == 10002) {
               // send email
               // log it to database
               echo $e->getMessage();
           } else
               // handle scenario when code details where not found
               if($e->getStatus() == 404 && $e->getErrorCode() == 50002) {
                   // error when image binary data cannot be found within additional request
                   // after order is made this shouldn't occurred
                   echo $e->getMessage();
               } else
                   // handle scenario when product was not found in price list
                   if($e->getStatus() == 404 && $e->getErrorCode() == 20001) {
                       // error can occurred when you present e.g. some old products that are now excluded from price list.
                       // redirect user to some error page
                   } else
                       // handle when quantity was less then 1
                       if($e->getStatus() == 400 && $e->getErrorCode() == 40002) {
                           // the input data was not validated on your side and passed to CWS
                           // quantity can't be <= 0
                           echo $e->getMessage();
                       } else {
                           // handle general app error
                           // Log it to database, and give us a shout if it's our false at devteam@codeswholesale.com
                           echo $e->getCode();
                           echo $e->getErrorCode();
                           echo $e->getMoreInfo();
                           echo $e->getDeveloperMessage();
                           echo $e->getMessage();
                       }*/
         return null;
     }
 }
Ejemplo n.º 3
0
 public function purchase($cwProductId, $qty)
 {
     $cwProduct = \CodesWholesale\Resource\Product::get($cwProductId);
     $codes = \CodesWholesale\Resource\Order::createBatchOrder($cwProduct, array('quantity' => $qty));
     $cwOrderId = $codes->getOrderId();
     $preOrders = 0;
     $links = array();
     foreach ($codes as $code) {
         if ($code->isPreOrder()) {
             $preOrders++;
         }
         $links[] = $code->getHref();
     }
     $orderedCodesArray = array('cwOrderId' => $cwOrderId, 'links' => $links, 'preOrders' => $preOrders);
     return $orderedCodesArray;
 }
  * \CodesWholesale\Resource\Product::get($url);
  *
  */
 /**
  * Sample products
  */
 // $url = "https://sandbox.codeswholesale.com/v1/products/33e3e81d-2b78-475a-8886-9848116f5133"; // - pre order product
 // $url = "https://sandbox.codeswholesale.com/v1/products/04aeaf1e-f7b5-4ba9-ba19-91003a04db0a"; // - not enough balance
 // $url = "https://sandbox.codeswholesale.com/v1/products/6313677f-5219-47e4-a067-7401f55c5a3a"; // - image code
 $url = "https://sandbox.codeswholesale.com/v1/products/ffe2274d-5469-4b0f-b57b-f8d21b09c24c";
 // - code text
 $product = \CodesWholesale\Resource\Product::get($url);
 /**
  * Make an order for this particular product for 15s codes
  */
 $codes = \CodesWholesale\Resource\Order::createBatchOrder($product, array('quantity' => 10));
 /**
  * Go through bought codes
  */
 foreach ($codes as $code) {
     /**
      * There are 3 possible code types returned from CW.
      *
      * Pre Order (when codes are not in stock)
      */
     if ($code->isPreOrder()) {
         // nothing much to do with PreOrdered code - we are working on Post Back functionality,
         // CW will send you a post back information
         // once the code is added to your order, post back will be send directly to your website.
         // For now you can send an notification email
         echo "Pre-order <br />";