public function testAddOneItemToBasketWithAppId()
 {
     $api = $this->getAY();
     $item = new Basket\BasketItem('1234', $this->getVariantId(1), array('description' => 'test', 'image_url' => 'http://www.google.de', 'foo' => 'bar'), 200);
     $basket = new Basket();
     $basket->updateItem($item);
     $basket = $api->updateBasket($this->getSessionId(), $basket);
     $item = $basket->getItem('1234');
     $this->assertEquals(1, $basket->getTotalAmount());
     $this->assertEquals(200, $item->getAppId());
     $this->assertInstanceOf('\\AboutYou\\SDK\\Model\\Basket\\BasketItem', $item);
     $data = $item->getAdditionalData();
     $this->assertEquals('test', $data['description']);
     $this->assertEquals('http://www.google.de', $data['image_url']);
     $this->assertEquals('bar', $data['foo']);
     $basket->deleteAllItems();
     $api->updateBasket($this->getSessionId(), $basket);
 }
    /**
     * @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);
    }
Ejemplo n.º 3
0
 /**
  * Adds a single item into the basket.
  * You can specify an amount. Please mind, that an amount > 1 will result in #amount basket positions.
  * So if you read out the basket again later, it's your job to merge the positions again.
  *
  * It is highly recommend to use the basket update method, to manage your items.
  *
  * @param string  $sessionId
  * @param integer $variantId
  * @param integer $amount
  * @param bool    $cleanErrors   Return all errors and then removes them from any further responses
  * @param bool    $refresh       Updates all products and variants
  *
  * @return Basket
  *
  * @throws \InvalidArgumentException
  */
 public function addItemToBasket($sessionId, $variantId, $amount = 1, $cleanErrors = true, $refresh = true)
 {
     if (!is_long($variantId)) {
         if (is_string($variantId) && ctype_digit($variantId)) {
             $variantId = intval($variantId);
         } else {
             throw new \InvalidArgumentException('the variant id must be an integer or string with digits');
         }
     }
     $basket = new Basket();
     for ($i = 0; $i < $amount; $i++) {
         $item = new Basket\BasketItem(null, $variantId);
         $basket->updateItem($item);
     }
     return $this->updateBasket($sessionId, $basket, $cleanErrors, $refresh);
 }