addProduct() public method

add a delivery method into the pool.
public addProduct ( string $code, ProductDefinition $productDescription )
$code string
$productDescription ProductDefinition
Ejemplo n.º 1
0
 public function testBuild()
 {
     $productProvider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $productManager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $definition = new ProductDefinition($productProvider, $productManager);
     $productPool = new ProductPool();
     $productPool->addProduct('test', $definition);
     $deliveryPool = new DeliveryPool();
     $paymentPool = new PaymentPool();
     $address = $this->getMock('Sonata\\Component\\Customer\\AddressInterface');
     $addressManager = $this->getMock('Sonata\\Component\\Customer\\AddressManagerInterface');
     $addressManager->expects($this->exactly(2))->method('findOneBy')->will($this->returnValue($address));
     $basketBuilder = new BasketBuilder($productPool, $addressManager, $deliveryPool, $paymentPool);
     $basketElement_1 = $this->getMock('Sonata\\Component\\Basket\\BasketElementInterface');
     $basketElement_1->expects($this->exactly(2))->method('getProductCode')->will($this->returnValue('test'));
     $basketElement_1->expects($this->once())->method('setProductDefinition');
     $basketElements = array($basketElement_1);
     $basket = $this->getMock('Sonata\\Component\\Basket\\BasketInterface');
     $basket->expects($this->once())->method('getBasketElements')->will($this->returnValue($basketElements));
     $basket->expects($this->once())->method('getDeliveryAddressId')->will($this->returnValue(1));
     $basket->expects($this->once())->method('getDeliveryMethodCode')->will($this->returnValue('ups'));
     $basket->expects($this->once())->method('getBillingAddressId')->will($this->returnValue(2));
     $basket->expects($this->once())->method('getPaymentMethodCode')->will($this->returnValue('credit_cart'));
     $basket->expects($this->once())->method('setDeliveryAddress');
     $basket->expects($this->once())->method('setDeliveryMethod');
     $basket->expects($this->once())->method('setBillingAddress');
     $basket->expects($this->once())->method('setPaymentMethod');
     $basket->expects($this->once())->method('buildPrices');
     $basketBuilder->build($basket);
 }
Ejemplo n.º 2
0
 public function testPool()
 {
     $productProvider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $productManager1 = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $productManager2 = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     // we need products from different objects to test ProductPool
     $product1 = $this->getMock('Sonata\\Component\\Product\\ProductInterface');
     $product2 = new Product();
     $productManager1->expects($this->any())->method('getClass')->will($this->returnValue($product1));
     $productManager2->expects($this->any())->method('getClass')->will($this->returnValue($product2));
     $definition1 = new ProductDefinition($productProvider, $productManager1);
     $definition2 = new ProductDefinition($productProvider, $productManager2);
     $productPool = new Pool();
     $productPool->addProduct('product1', $definition1);
     $productPool->addProduct('product2', $definition2);
     $this->assertFalse($productPool->hasProvider('grou'));
     $this->assertTrue($productPool->hasProvider('product1'));
     $this->assertTrue($productPool->hasProvider('product2'));
     $this->assertEquals($productPool->getProduct('product1'), $definition1);
     $this->assertEquals($productPool->getProduct('product2'), $definition2);
     $this->assertEquals($productPool->getProductCode($product1), 'product1');
     $this->assertEquals($productPool->getProductCode($product2), 'product2');
 }
Ejemplo n.º 3
0
 protected function getPreparedBasket()
 {
     $basket = new Basket();
     // create the provider mock
     $provider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $provider->expects($this->any())->method('basketCalculatePrice')->will($this->returnValue(15));
     $provider->expects($this->any())->method('isAddableToBasket')->will($this->returnValue(true));
     // create the product manager mock
     $manager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $manager->expects($this->any())->method('getClass')->will($this->returnValue('BasketTest_Product'));
     $definition = new ProductDefinition($provider, $manager);
     $pool = new Pool();
     $pool->addProduct('product_code', $definition);
     $basket->setProductPool($pool);
     return $basket;
 }