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; }
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; }
public function process() { if ($this->cwProductId == null) { $request = file_get_contents('php://input'); if (empty($request)) { die("No request data"); } $cwProductId = $this->connection->receiveUpdatedProductId(); } try { $product = \CodesWholesale\Resource\Product::get($cwProductId); } catch (\CodesWholesale\Resource\ResourceError $e) { die("Received product id: " . $cwProductId . " Error: " . $e->getMessage()); } $quantity = $product->getStockQuantity(); $price = $product->getLowestPrice(); $priceSpread = $this->spreadCalculator->calculateSpread($this->spreadParams->getSpreadParams(), $price); $this->productUpdater->updateProduct($cwProductId, $quantity, $priceSpread); }
*/ $products = $client->getProducts(); /** * Chose an random product */ $randomIndex = rand(0, count($products) - 1); $randomProduct = $products->get($randomIndex); /** * Find a product by Href this is an id of product. * * Or directly by href url * * $url = "https://api.codeswholesale.com/v1/products/8cc3f405-8453-4031-be49-f826814faa0c"; * \CodesWholesale\Resource\Product::get($url); * */ $product = \CodesWholesale\Resource\Product::get($randomProduct->getHref()); /** * Included from utils.php, displaying product details, just for testing purposes */ displayProductDetails($product); } catch (\CodesWholesale\Resource\ResourceError $e) { if ($e->isInvalidToken()) { echo "if you are using SessionStorage refresh your session and try one more time."; } echo $e->getCode(); echo $e->getErrorCode(); echo $e->getMoreInfo(); echo $e->getDeveloperMessage(); echo $e->getMessage(); }
* * Or directly by href url * * $url = "https://api.sandbox.codeswholesale.com/v1/products/8cc3f405-8453-4031-be49-f826814faa0c"; * \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,