Beispiel #1
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;
 }
Beispiel #2
0
 /**
  * @param CartItem $cartItem
  * @param Cart     $cart
  *
  * @return $this
  */
 protected function updateCartItem(CartItem $cartItem, Cart $cart)
 {
     $cartItem->setCart($cart);
     $this->em->persist($cartItem);
     return $this;
 }
Beispiel #3
0
 /**
  * @param int $originId
  *
  * @return CartItem
  */
 protected function getCartItem($originId)
 {
     $cartItem = new CartItem();
     $cartItem->setOriginId($originId);
     return $cartItem;
 }