示例#1
0
 /**
  * Test setting removed field on removed cart items
  */
 public function testUpdateRemovedCartItems()
 {
     $channel = new Channel();
     $cartItem1 = new CartItem();
     $cartItem1->setName('Cart Item 1');
     $cartItem2 = new CartItem();
     $cartItem2->setName('Cart Item 2');
     $cartItem3 = new CartItem();
     $cartItem3->setName('Cart Item 3');
     $existingCartItems = new ArrayCollection();
     $existingCartItems->add($cartItem1);
     $existingCartItems->add($cartItem2);
     $existingCart = new Cart();
     $existingCart->setCartItems($existingCartItems);
     $existingCart->setChannel($channel);
     $existingCart->setItemsQty(2);
     $newCartItems = new ArrayCollection();
     $newCartItems->add($cartItem2);
     $newCartItems->add($cartItem3);
     $newCart = new Cart();
     $newCart->setCartItems($newCartItems);
     $newCart->setChannel($channel);
     $newCart->setItemsQty(2);
     $this->databaseHelper->expects($this->once())->method('findOneByIdentity')->will($this->returnValue($existingCart));
     $this->databaseHelper->expects($this->once())->method('getEntityReference')->will($this->returnValue($channel));
     $this->databaseHelper->expects($this->once())->method('getIdentifier')->will($this->returnValue('identifier'));
     $this->databaseHelper->expects($this->once())->method('find')->with('OroCRM\\Bundle\\MagentoBundle\\Entity\\Cart', 'identifier')->will($this->returnValue($newCart));
     $strategy = $this->getStrategy();
     /** @var \PHPUnit_Framework_MockObject_MockObject|ContextInterface $context */
     $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface');
     $strategy->setImportExportContext($context);
     $strategy->setEntityName('OroCRM\\Bundle\\MagentoBundle\\Entity\\Cart');
     $execution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext');
     $this->jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($execution));
     $strategy->setStepExecution($this->stepExecution);
     $strategy->process($existingCart);
     $this->assertTrue($cartItem1->isRemoved());
     $this->assertFalse($cartItem2->isRemoved());
     $this->assertFalse($cartItem3->isRemoved());
 }
示例#2
0
 /**
  * @return CartItem
  */
 protected function createCartItem()
 {
     $cartItem = new CartItem();
     $cartItem->setName('item' . mt_rand(0, 99999));
     $cartItem->setDescription('something');
     $cartItem->setPrice(mt_rand(10, 99999));
     $cartItem->setProductId(1);
     $cartItem->setFreeShipping('true');
     $cartItem->setIsVirtual(1);
     $cartItem->setRowTotal(100);
     $cartItem->setTaxAmount(10);
     $cartItem->setProductType('type');
     $cartItem->setSku('sku');
     $cartItem->setQty(0);
     $cartItem->setDiscountAmount(0);
     $cartItem->setTaxPercent(0);
     $cartItem->setCreatedAt(new \DateTime('now'));
     $cartItem->setUpdatedAt(new \DateTime('now'));
     $this->em->persist($cartItem);
     return $cartItem;
 }
示例#3
0
 /**
  * @param ObjectManager $om
  * @param Cart          $cart
  *
  * @return CartItem[]
  */
 protected function generateShoppingCartItem(ObjectManager $om, Cart $cart)
 {
     $products = array('Computer', 'Gaming Computer', 'Universal Camera Case', 'SLR Camera Tripod', 'Two Year Extended Warranty - Parts and Labor', 'Couch', 'Chair', 'Magento Red Furniture Set');
     $cartItems = array();
     $cartItemsCount = rand(0, 2);
     $total = 0.0;
     $totalTaxAmount = 0.0;
     $shipping = rand(0, 1);
     for ($i = 0; $i <= $cartItemsCount; $i++) {
         $product = $products[rand(0, count($products) - 1)];
         $origin = $i + 1;
         $price = rand(10, 200);
         $price = $price + rand(0, 99) / 100.0;
         $taxAmount = $price * self::VAT;
         $totalTaxAmount = $totalTaxAmount + $taxAmount;
         $total = $total + $price + $taxAmount;
         $cartItem = new CartItem();
         $cartItem->setProductId(rand(1, 100));
         $cartItem->setFreeShipping((string) $shipping);
         $cartItem->setIsVirtual(0);
         $cartItem->setRowTotal($price + $taxAmount);
         $cartItem->setPriceInclTax($price + $taxAmount);
         $cartItem->setTaxAmount($taxAmount);
         $cartItem->setSku('sku-' . $product);
         $cartItem->setProductType('simple');
         $cartItem->setName($product);
         $cartItem->setQty(1);
         $cartItem->setPrice($price);
         $cartItem->setDiscountAmount(0);
         $cartItem->setTaxPercent(self::VAT);
         $cartItem->setCreatedAt(new \DateTime('now'));
         $cartItem->setUpdatedAt(new \DateTime('now'));
         $cartItem->setOriginId($origin);
         $cartItem->setCart($cart);
         $cart->getCartItems()->add($cartItem);
         $cart->setItemsQty($i + 1);
         $cart->setItemsCount($i + 1);
         $om->persist($cartItem);
         $cartItems[] = $cartItem;
     }
     $cart->setSubTotal($total);
     $shippingAmount = 0.0;
     if ((bool) $shipping) {
         $shippingAmount = rand(3, 10);
     }
     $cart->setGrandTotal($total + $shippingAmount);
     $cart->setTaxAmount($totalTaxAmount);
     $om->persist($cart);
     return $cartItems;
 }