Ejemplo n.º 1
0
 /**
  * @param BasketItem $basketItem
  *
  * @return $this
  */
 public function updateItem(BasketItem $basketItem)
 {
     $itemId = $basketItem->getId();
     $item = array('variant_id' => $basketItem->getVariantId(), 'app_id' => $basketItem->getAppId());
     if ($itemId) {
         $item['id'] = $itemId;
     }
     $additionalData = $basketItem->getAdditionalData();
     if (!empty($additionalData)) {
         $this->checkAdditionData($additionalData);
         $item['additional_data'] = (array) $additionalData;
     }
     if ($itemId) {
         $this->updatedItems[$basketItem->getId()] = $item;
     } else {
         $this->updatedItems[] = $item;
     }
     return $this;
 }
    /**
     * @depends testBasket
     */
    public function testUpdateBasket(Basket $basket)
    {
        $this->markTestSkipped('This test is useless');
        $exceptedRequestBody = '[{"basket":{"session_id":"testing"}}]';
        $ay = $this->getAYWithResultFile('result/basket1.json', $exceptedRequestBody);
        $basket = $ay->updateBasket($this->sessionId, $basket);
        $this->checkBasket($basket);
        $basket->deleteItem('item3');
        $exceptedRequestBody = '[{"basket":{"session_id":"testing","order_lines":[{"delete":"item3"}]}}]';
        $ay = $this->getAYWithResultFile('result/basket1.json', $exceptedRequestBody);
        $ay->updateBasket($this->sessionId, $basket);
        $basket = Basket::createFromJson(json_decode('{"products":[], "order_line":[], "total_price":123, "total_net":12,"total_vat":34}'), $ay->getResultFactory());
        $basket->updateItem(new Basket\BasketItem('item1', 123));
        $exceptedRequestBody = '[{"basket":{"session_id":"testing","order_lines":[{"variant_id":123,"app_id":null,"id":"item1"}]}}]';
        $ay = $this->getAYWithResultFile('result/basket1.json', $exceptedRequestBody);
        $ay->updateBasket($this->sessionId, $basket);
        $basket = new Basket();
        $basket->updateItem(new Basket\BasketItem(null, 123));
        $exceptedRequestBody = '[{"basket":{"session_id":"testing","order_lines":[{"variant_id":123,"app_id":null}]}}]';
        $ay = $this->getAYWithResultFile('result/basket1.json', $exceptedRequestBody);
        $ay->updateBasket($this->sessionId, $basket);
        $basket = new Basket();
        $basket->updateItem(new Basket\BasketItem('item2', 123));
        $exceptedRequestBody = '[{"basket":{"session_id":"testing","order_lines":[{"variant_id":123,"app_id":null,"id":"item2"}]}}]';
        $ay = $this->getAYWithResultFile('result/basket1.json', $exceptedRequestBody);
        $ay->updateBasket($this->sessionId, $basket);
        $basket = new Basket();
        $basket->updateItem(new Basket\BasketItem('item3', 123, array('description' => 'Wudnerschön')));
        $exceptedRequestBody = '[{"basket":{"session_id":"testing","order_lines":[{"variant_id":123,"app_id":null,"id":"item3","additional_data":{"description":"Wudnersch\\u00f6n"}}]}}]';
        $ay = $this->getAYWithResultFile('result/basket1.json', $exceptedRequestBody);
        $ay->updateBasket($this->sessionId, $basket);
        $basket = new Basket();
        $item = new Basket\BasketItem('item3', 123);
        $item->setAdditionData(array('description' => 'Wudnerschön'));
        $basket->updateItem($item);
        $exceptedRequestBody = '[{"basket":{"session_id":"testing","order_lines":[{"variant_id":123,"app_id":null,"id":"item3","additional_data":{"description":"Wudnersch\\u00f6n"}}]}}]';
        $ay = $this->getAYWithResultFile('result/basket1.json', $exceptedRequestBody);
        $ay->updateBasket($this->sessionId, $basket);
        $updatedItem4 = <<<EOS
        {
            "additional_data": {"description": "Wudnersch\\u00f6n und so", "image_url": "http://google.de"},
            "set_items": [
                {
                    "variant_id": 12312121,
                    "app_id":null
                },
                {
                    "variant_id": 66666,
                    "app_id":null,
                    "additional_data": {
                        "description": "engravingssens",
                        "internal_infos":["stuff"]
                    }
                }
            ],
            "id": "identifier4"
        }
EOS;
        $updatedItem4 = json_encode(json_decode($updatedItem4));
        // reformat
        $basket = new Basket();
        $basket->updateItemSet(Basket\BasketSet::create('identifier4', array(array(12312121), array(66666, array('description' => 'engravingssens', 'internal_infos' => array('stuff')))), array('description' => 'Wudnerschön und so', "image_url" => "http://google.de")));
        $exceptedRequestBody = '[{"basket":{"session_id":"testing","order_lines":[' . $updatedItem4 . ']}}]';
        $ay = $this->getAYWithResultFile('result/basket1.json', $exceptedRequestBody);
        $ay->updateBasket($this->sessionId, $basket);
    }
 /**
  * {@inheritdoc}
  *
  * @return Basket\BasketItem
  */
 public function createBasketItem(stdClass $jsonObject, array $products)
 {
     return Basket\BasketItem::createFromJson($jsonObject, $products);
 }