Example #1
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'));
     $cartItem->setOwner($this->organization);
     $this->em->persist($cartItem);
     return $cartItem;
 }
Example #2
0
 /**
  * @param ObjectManager $om
  * @param Cart          $cart
  *
  * @return CartItem[]
  */
 protected function generateShoppingCartItem(ObjectManager $om, Cart $cart)
 {
     $products = ['Computer', 'Gaming Computer', 'Universal Camera Case', 'SLR Camera Tripod', 'Two Year Extended Warranty - Parts and Labor', 'Couch', 'Chair', 'Magento Red Furniture Set'];
     $cartItems = [];
     $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::TAX;
         $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::TAX);
         $cartItem->setCreatedAt(new \DateTime('now'));
         $cartItem->setUpdatedAt(new \DateTime('now'));
         $cartItem->setOriginId($origin);
         $cartItem->setCart($cart);
         $cartItem->setOwner($cart->getOrganization());
         $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;
 }