예제 #1
0
 public function testAddProduct()
 {
     $productCollection = new ProductCollection();
     $priceCollection = new PriceCollection();
     $priceAvista = new Product\Price(['type' => Product\Price::TYPE_BOLETO, 'price' => 99.98999999999999]);
     $priceCollection->add($priceAvista);
     $priceParcelado = new Product\Price(['type' => Product\Price::TYPE_CARTAO_PARCELADO_SEM_JUROS, 'price' => 99.98999999999999, 'installment' => 3, 'installmentValue' => 33.33]);
     $priceCollection->add($priceParcelado);
     $product1 = new Product(['sku' => 'unit', 'prices' => $priceCollection, 'quantity' => 1, 'category' => 'Unit > Test', 'description' => 'Test unit to product', 'images' => [['url' => 'http://image.com/teste1.jpg'], ['url' => 'http://image.com/teste2.jpg']], 'link' => 'http://link.com/unit', 'technicalSpecification' => [['key' => 'Unit', 'value' => 'Use'], ['key' => 'Another', 'value' => 'Unit']], 'sizeHeight' => 10, 'sizeLength' => 10, 'sizeWidth' => 10, 'weightValue' => 0, 'marketplace' => 'PHP Unit']);
     $productCollection->add($product1);
     $product2 = new Product(['sku' => 'unit101001', 'prices' => [['type' => Product\Price::TYPE_CARTAO_AVISTA, 'price' => 50.5], ['type' => Product\Price::TYPE_CARTAO_PARCELADO_SEM_JUROS, 'price' => 50.5, 'installment' => 2, 'installmentValue' => 25.25]], 'quantity' => 2, 'category' => 'Unit > Test', 'description' => 'Test unit to product<br>', 'images' => [['url' => 'http://image.com/teste3.jpg'], ['url' => 'http://image.com/teste4.jpg']], 'link' => 'http://link.com/unit2', 'technicalSpecification' => [['key' => 'Unit2', 'value' => 'Use'], ['key' => 'Another', 'value' => 'Unit2']], 'sizeHeight' => 9, 'sizeLength' => 8, 'sizeWidth' => 7, 'weightValue' => 6, 'marketplace' => 'PHP Unit', 'barcode' => '123']);
     $productCollection->add($product2);
 }
예제 #2
0
 /**
  * Expected data for Request
  *
  * @param  \Mobly\Buscape\Sdk\Collection\ProductCollection $collection
  * @param  integer $chunk
  * @return array
  **/
 protected function getRequestExpected(ProductCollection $collection, $chunk)
 {
     $paginator = new Paginator($collection->toArray(), $chunk);
     $response = [];
     foreach ($paginator as $page) {
         $code = 0;
         foreach ($page as $key => $productEntity) {
             $product = $productEntity->toArray();
             $error = 0 == $key || $key % 2;
             $tmp = ['sku' => $product['sku'], 'status' => $error];
             if (!$error) {
                 $tmp['errors'][] = ['code' => $code, 'message' => 'error message no. ' . $code];
                 $code++;
             }
             $response[] = $tmp;
         }
     }
     return $response;
 }
예제 #3
0
 /**
  * Merge data from Buscape with the ccollection of products and set the this data property
  *
  * @param ProductCollection $products
  * @param $responseData
  */
 public function mergeData(ProductCollection $products, $responseData)
 {
     $this->data = new ProductCollection();
     if ($products->getErrors()) {
         $this->data->addValidationResponse($products->getErrors());
     }
     foreach ($products as $key => $product) {
         if (empty($responseData[$key])) {
             continue;
         }
         if (!empty($responseData[$key]['status'])) {
             $product->setStatus($responseData[$key]['status']);
         }
         if (!empty($responseData[$key]['errors'])) {
             $product->setErrors($responseData[$key]['errors']);
         }
         $this->data->addProductResponse($product);
     }
 }