public function testReplaceCartItemsChildrenReplacesAllChildCartItemsWithNewItemsBuiltFromFlatOptions()
 {
     $flatOptions = array(22 => 33);
     $cartItem = $this->getMock('\\SpeckCart\\Entity\\CartItem');
     $cartItem->expects($this->any())->method('getCartItemId')->will($this->returnValue(1));
     $meta = $this->getMock('SpeckCatalog\\Model\\CartItemMeta');
     $meta->expects($this->any())->method('getProductId')->will($this->returnValue('99'));
     $meta->expects($this->any())->method('setFlatOptions')->with($flatOptions);
     $childCartItem = $this->getMock('\\SpeckCart\\Entity\\CartItem');
     $childCartItem->expects($this->any())->method('getCartItemId')->will($this->returnValue(8));
     $items = array($childCartItem);
     $cartItem->expects($this->any())->method('getItems')->will($this->returnValue($items));
     $cartItem->expects($this->any())->method('getMetadata')->will($this->returnValue($meta));
     $mockCart = $this->getMock('\\SpeckCart\\Entity\\Cart');
     $mockCart->expects($this->any())->method('getItems')->will($this->returnValue(array($cartItem)));
     $mockSpeckCartService = $this->getMock('\\SpeckCart\\Service\\CartService');
     $mockSpeckCartService->expects($this->once())->method('getSessionCart')->will($this->returnValue($mockCart));
     $choice1 = new \SpeckCatalog\Model\Choice\Relational();
     $choice1->setChoiceId(33);
     $option = new \SpeckCatalog\Model\Option\Relational();
     $option->setOptionId(22)->setChoices(array($choice1));
     $product = new \SpeckCatalog\Model\Product\Relational();
     $product->setOptions(array($option));
     $mockProductService = $this->getMock('\\SpeckCatalog\\Service\\Product');
     $mockProductService->expects($this->any())->method('getFullProduct')->will($this->returnValue($product));
     $service = $this->getService();
     $service->setCartService($mockSpeckCartService);
     $service->setProductService($mockProductService);
     $mockSpeckCartService->expects($this->once())->method('removeItemFromCart')->with(8);
     $mockSpeckCartService->expects($this->once())->method('addItemToCart');
     $mockSpeckCartService->expects($this->once())->method('persistItem');
     $service->replaceCartItemsChildren(1, $flatOptions);
 }
 public function testGetRecursivePriceWithMultipleNestedChoices()
 {
     $choice = new \SpeckCatalog\Model\Choice\Relational();
     $option = new \SpeckCatalog\Model\Option\Relational();
     $option->setRequired(true);
     $nestedChoice = new \SpeckCatalog\Model\Choice\Relational();
     $nestedChoice1 = new \SpeckCatalog\Model\Choice\Relational();
     $optionMock = $this->getMockBuilder('\\SpeckCatalog\\Model\\Option\\Relational')->getMock();
     $optionMock->expects($this->any())->method('getAdjustedPrice')->will($this->returnValue(1000));
     $choice->setParent($optionMock);
     $option->addChoice($nestedChoice);
     $option->addChoice($nestedChoice1);
     $choice->addOption($option);
     $this->assertEquals(0, $choice->getRecursivePrice(1000));
     $nestedChoice->setPriceDiscountFixed(100);
     $nestedChoice1->setPriceDiscountFixed(101);
     $this->assertEquals(-101, $choice->getRecursivePrice(1000));
     $nestedChoice->setPriceDiscountFixed(null);
     $nestedChoice->setPriceDiscountPercent(10);
     $this->assertEquals(-101, $choice->getRecursivePrice(1000));
     $nestedChoice->setPriceDiscountPercent(null);
     $nestedChoice->setPriceOverrideFixed(50);
     $this->assertEquals(-950, $choice->getRecursivePrice(1000));
     $nestedChoice->setPriceOverrideFixed(null);
     $nestedChoice->setPriceNoCharge(1);
     $this->assertEquals(-1000, $choice->getRecursivePrice(1000));
     $nestedChoice1->setPriceDiscountFixed(null);
     $nestedChoice1->setPriceNoCharge(1);
     $nestedChoice->setPriceNoCharge(1);
     $this->assertEquals(-1000, $choice->getRecursivePrice(1000));
 }
示例#3
0
 public function testGetAddPriceWithNestedOptions()
 {
     $product = $this->getMockBuilder('\\SpeckCatalog\\Model\\Product\\Relational')->getMock();
     $product->expects($this->any())->method('getPrice')->will($this->returnValue(1000));
     $product1 = $this->getMockBuilder('\\SpeckCatalog\\Model\\Product\\Relational')->getMock();
     $product1->expects($this->any())->method('getPrice')->will($this->returnValue(500));
     $option = new \SpeckCatalog\Model\Option\Relational();
     $option->setParent($product);
     $choice = new \SpeckCatalog\Model\Choice\Relational();
     $option->addChoice($choice);
     $choice1 = new \SpeckCatalog\Model\Choice\Relational();
     $choice1->setProduct($product1);
     $option->addChoice($choice1);
     $choice2 = new \SpeckCatalog\Model\Choice\Relational();
     $option1 = new \SpeckCatalog\Model\Option\Relational();
     $option1->addChoice($choice2);
     $choice->addOption($option1);
     $this->assertEquals(0, $choice2->getAddPrice());
     $this->assertEquals(500, $choice1->getAddPrice());
     $this->assertEquals(0, $choice->getAddPrice());
     $choice2->setPriceDiscountFixed(100);
     $this->assertEquals(-100, $choice2->getAddPrice());
     $this->assertEquals(500, $choice1->getAddPrice());
     $this->assertEquals(0, $choice->getAddPrice());
     $choice1->setPriceDiscountFixed(100);
     $this->assertEquals(-100, $choice2->getAddPrice());
     $this->assertEquals(400, $choice1->getAddPrice());
     $this->assertEquals(0, $choice->getAddPrice());
     $choice->setPriceDiscountFixed(100);
     $this->assertEquals(-100, $choice2->getAddPrice());
     $this->assertEquals(400, $choice1->getAddPrice());
     $this->assertEquals(-100, $choice->getAddPrice());
     $choice->setPriceDiscountFixed(null);
     $choice1->setPriceDiscountFixed(null);
     $choice2->setPriceDiscountFixed(null);
     $choice->setPriceDiscountPercent(10);
     $this->assertEquals(-100, $choice->getAddPrice());
     $this->assertEquals(500, $choice1->getAddPrice());
     $this->assertEquals(0, $choice2->getAddPrice());
     $choice1->setPriceDiscountPercent(15);
     $this->assertEquals(-100, $choice->getAddPrice());
     $this->assertEquals(425, $choice1->getAddPrice());
     $this->assertEquals(0, $choice2->getAddPrice());
     $choice2->setPriceDiscountPercent(20);
     $this->assertEquals(-100, $choice->getAddPrice());
     $this->assertEquals(425, $choice1->getAddPrice());
     $this->assertEquals(-180, $choice2->getAddPrice());
     $choice->setPriceDiscountPercent(null);
     $choice1->setPriceDiscountPercent(null);
     $choice2->setPriceDiscountPercent(null);
     $choice->setPriceOverrideFixed(950);
     $this->assertEquals(-50, $choice->getAddPrice());
     $this->assertEquals(500, $choice1->getAddPrice());
     $this->assertEquals(0, $choice2->getAddPrice());
     $choice1->setPriceOverrideFixed(425);
     $this->assertEquals(-50, $choice->getAddPrice());
     $this->assertEquals(425, $choice1->getAddPrice());
     $this->assertEquals(0, $choice2->getAddPrice());
     $choice2->setPriceOverrideFixed(800);
     $this->assertEquals(-50, $choice->getAddPrice());
     $this->assertEquals(425, $choice1->getAddPrice());
     $this->assertEquals(-150, $choice2->getAddPrice());
     $choice->setPriceOverrideFixed(null);
     $choice1->setPriceOverrideFixed(null);
     $choice2->setPriceOverrideFixed(null);
     $choice->setPriceNoCharge(1);
     $this->assertEquals(-1000, $choice->getAddPrice());
     $this->assertEquals(500, $choice1->getAddPrice());
     $this->assertEquals(0, $choice2->getAddPrice());
     $choice1->setPriceNoCharge(1);
     $this->assertEquals(-1000, $choice->getAddPrice());
     $this->assertEquals(0, $choice1->getAddPrice());
     $this->assertEquals(0, $choice2->getAddPrice());
     $choice2->setPriceNoCharge(1);
     $this->assertEquals(-1000, $choice->getAddPrice());
     $this->assertEquals(0, $choice1->getAddPrice());
     $this->assertEquals(0, $choice2->getAddPrice());
 }