public function matches(CartItem $cartItem)
 {
     if ($cartItem->getProduct()->getId() == $this->product->getId() and $cartItem->getQuantity() >= $this->quantity) {
         return true;
     }
     return false;
 }
 public function __construct(Product $product, UuidInterface $id = null)
 {
     parent::__construct($id);
     $this->setFlagApplyCatalogPromotions(false);
     $this->product = $product;
     $product->addProductQuantityDiscount($this);
 }
Example #3
0
 public function testRandWithSeed()
 {
     $qb = $this->entityManager->createQueryBuilder();
     $randomProducts = $qb->select('Product')->from(Product::class, 'Product')->addSelect('RAND(:rand) as HIDDEN rand')->orderBy('rand')->setParameter('rand', crc32($this->product1->getId()))->getQuery()->getResult();
     $this->assertSame(3, count($randomProducts));
     $this->assertTrue(in_array($this->product1, $randomProducts));
     $this->assertTrue(in_array($this->product2, $randomProducts));
     $this->assertTrue(in_array($this->product3, $randomProducts));
 }
 public function __construct(User $user, Product $product, Attachment $attachment, UuidInterface $id = null)
 {
     if (!$product->areAttachmentsEnabled()) {
         throw AttachmentException::notAllowed();
     }
     $this->setId($id);
     $this->setCreated();
     $this->user = $user;
     $this->product = $product;
     $this->attachment = $attachment;
 }
 public function isTagValid(Product $product)
 {
     if ($this->tag === null) {
         return true;
     }
     foreach ($product->getTags() as $tag) {
         if ($tag->getId() !== null and $tag->getId() == $this->tag->getId()) {
             return true;
         }
     }
     return false;
 }
 public function getPrice(Product $product, $quantity)
 {
     $this->product = $product;
     $this->quantity = $quantity;
     $this->price = new Price();
     $this->price->origUnitPrice = $this->product->getUnitPrice();
     $this->price->origQuantityPrice = $this->price->origUnitPrice * $this->quantity;
     $this->price->unitPrice = $this->price->origUnitPrice;
     $this->calculateProductQuantityDiscounts();
     $this->calculateCatalogPromotions();
     $this->calculateQuantityPrice();
     return $this->price;
 }
 /**
  * @return static
  */
 public function withProductAttributes()
 {
     foreach ($this->entity->getProductAttributes() as $productAttribute) {
         $this->entityDTO->productAttributes[] = $this->dtoBuilderFactory->getProductAttributeDTOBuilder($productAttribute)->withAttribute()->withAttributeValue()->build();
     }
     return $this;
 }
Example #8
0
 public function areAttachmentsEnabled()
 {
     if ($this->product !== null) {
         return $this->product->areAttachmentsEnabled();
     }
     return false;
 }
 public function testGetPriceWithProductQuantityDiscountPercent()
 {
     $product = new Product();
     $product->setUnitPrice(500);
     $productQuantityDiscount6 = new ProductQuantityDiscount($product);
     $productQuantityDiscount6->setType(PromotionType::percent());
     $productQuantityDiscount6->setQuantity(6);
     $productQuantityDiscount6->setValue(5);
     $productQuantityDiscount12 = new ProductQuantityDiscount($product);
     $productQuantityDiscount12->setType(PromotionType::percent());
     $productQuantityDiscount12->setQuantity(12);
     $productQuantityDiscount12->setValue(30);
     $productQuantityDiscount24 = new ProductQuantityDiscount($product);
     $productQuantityDiscount24->setType(PromotionType::percent());
     $productQuantityDiscount24->setQuantity(24);
     $productQuantityDiscount24->setValue(35);
     $productQuantityDiscounts = $product->getProductQuantityDiscounts();
     $this->pricing->setProductQuantityDiscounts($productQuantityDiscounts);
     $expectedPrice = new Price();
     $expectedPrice->unitPrice = 500;
     $expectedPrice->origUnitPrice = 500;
     $expectedPrice->quantityPrice = 500;
     $expectedPrice->origQuantityPrice = 500;
     $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 1));
     $expectedPrice = new Price();
     $expectedPrice->unitPrice = 475;
     $expectedPrice->origUnitPrice = 500;
     $expectedPrice->quantityPrice = 2850;
     $expectedPrice->origQuantityPrice = 3000;
     $expectedPrice->addProductQuantityDiscount($productQuantityDiscount6);
     $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 6));
     $expectedPrice = new Price();
     $expectedPrice->unitPrice = 350;
     $expectedPrice->origUnitPrice = 500;
     $expectedPrice->quantityPrice = 4200;
     $expectedPrice->origQuantityPrice = 6000;
     $expectedPrice->addProductQuantityDiscount($productQuantityDiscount12);
     $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 12));
     $expectedPrice = new Price();
     $expectedPrice->unitPrice = 325;
     $expectedPrice->origUnitPrice = 500;
     $expectedPrice->quantityPrice = 7800;
     $expectedPrice->origQuantityPrice = 12000;
     $expectedPrice->addProductQuantityDiscount($productQuantityDiscount24);
     $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 24));
 }
 /**
  * @param Product $product
  * @param int $quantity
  * @throws InventoryException
  * @throws InsufficientInventoryException
  * @throws EntityValidatorException
  */
 public function reserveProduct(Product $product, $quantity)
 {
     if (!$product->isInventoryRequired()) {
         // TODO: Investigate throwing exception in this case
         return;
     }
     try {
         $inventoryHoldLocation = $this->inventoryLocationRepository->findOneById($this->inventoryHoldLocationId);
     } catch (EntityNotFoundException $e) {
         throw InventoryException::missingInventoryHoldLocation();
     }
     try {
         $inventoryLocationId = $this->inventoryTransactionRepository->findInventoryIdForProductAndQuantity($product, $quantity);
         $inventoryLocation = $this->inventoryLocationRepository->findOneById($inventoryLocationId);
     } catch (EntityNotFoundException $e) {
         throw new InsufficientInventoryException();
     }
     $this->transferProduct($product, $quantity, 'Hold ' . ngettext('item', 'items', $quantity) . ' for order', $inventoryLocation, $inventoryHoldLocation, InventoryTransactionType::hold());
 }
 public function testFindOneById()
 {
     $tag = $this->dummyData->getTag();
     $image = $this->dummyData->getImage();
     $sku = 'TST101';
     $name = 'Test Product';
     $description = 'Test description';
     $defaultImage = 'http://lorempixel.com/400/200/';
     $unitPrice = 500;
     $quantity = 10;
     $shippingWeight = 16;
     $rating = 500;
     $originalProduct = new Product();
     $originalProduct->setSku($sku);
     $originalProduct->setName($name);
     $originalProduct->setDescription($description);
     $originalProduct->setDefaultImage($defaultImage);
     $originalProduct->setUnitPrice($unitPrice);
     $originalProduct->setQuantity($quantity);
     $originalProduct->setShippingWeight($shippingWeight);
     $originalProduct->setRating($rating);
     $originalProduct->setIsInventoryRequired(true);
     $originalProduct->setIsPriceVisible(true);
     $originalProduct->setIsActive(true);
     $originalProduct->setIsVisible(true);
     $originalProduct->setIsTaxable(true);
     $originalProduct->setIsShippable(true);
     $originalProduct->enableAttachments();
     $originalProduct->addTag($tag);
     $originalProduct->addImage($image);
     $attribute = $this->dummyData->getAttribute();
     $attributeValue = $this->dummyData->getAttributeValue($attribute);
     $productAttribute = $this->dummyData->getProductAttribute($originalProduct, $attribute, $attributeValue);
     $option = $this->dummyData->getOption();
     $optionProduct = $this->dummyData->getOptionProduct($option, $originalProduct);
     $productQuantityDiscount = $this->dummyData->getProductQuantityDiscount($originalProduct);
     $this->persistEntityAndFlushClear([$tag, $image, $option, $optionProduct, $attribute, $attributeValue, $originalProduct]);
     $this->setCountLogger();
     $product = $this->productRepository->findOneById($originalProduct->getId());
     $this->assertEquals($originalProduct->getId(), $product->getId());
     $this->assertSame($sku, $product->getSku());
     $this->assertSame($name, $product->getName());
     $this->assertSame($description, $product->getDescription());
     $this->assertSame($defaultImage, $product->getDefaultImage());
     $this->assertSame($unitPrice, $product->getUnitPrice());
     $this->assertSame($quantity, $product->getQuantity());
     $this->assertSame($shippingWeight, $product->getShippingWeight());
     $this->assertSame(5, $product->getRating());
     $this->assertTrue($product->isInventoryRequired());
     $this->assertTrue($product->isPriceVisible());
     $this->assertTrue($product->isActive());
     $this->assertTrue($product->isvisible());
     $this->assertTrue($product->isTaxable());
     $this->assertTrue($product->isShippable());
     $this->assertTrue($product->areAttachmentsEnabled());
     $this->assertEquals($tag->getId(), $product->getTags()[0]->getId());
     $this->assertEquals($image->getId(), $product->getImages()[0]->getId());
     $this->assertEquals($productQuantityDiscount->getId(), $product->getProductQuantityDiscounts()[0]->getId());
     $this->assertEquals($optionProduct->getId(), $product->getOptionProducts()[0]->getId());
     $this->assertEquals($productAttribute->getId(), $product->getProductAttributes()[0]->getId());
     $this->assertSame(6, $this->getTotalQueries());
 }
Example #12
0
 public function areAttachmentsEnabled()
 {
     return $this->product->areAttachmentsEnabled();
 }
Example #13
0
 public function getProduct($sku = null)
 {
     if ($sku === null) {
         $sku = uniqid();
     }
     $product = new Product();
     $product->setSku($sku);
     $product->setName('Test Product');
     $product->setIsInventoryRequired(true);
     $product->setIsPriceVisible(true);
     $product->setIsActive(true);
     $product->setIsVisible(true);
     $product->setIsTaxable(true);
     $product->setIsShippable(true);
     $product->setShippingWeight(16);
     $product->setQuantity(10);
     $product->setUnitPrice(1200);
     return $product;
 }
Example #14
0
 public function testGetPrice()
 {
     $pricing = $this->dummyData->getPricing();
     $product = new Product();
     $product->setQuantity(1);
     $this->assertTrue($product->getPrice($pricing) instanceof Price);
 }
 public function testGetTotalWithZip5TaxAndCouponNoReduceSubtotal()
 {
     $product = new Product();
     $product->setUnitPrice(2000);
     $product->setIsTaxable(true);
     $taxRate = new TaxRate();
     $taxRate->setZip5(92606);
     $taxRate->setRate(8.0);
     $taxRate->setApplyToShipping(false);
     $coupon = $this->dummyData->getCoupon();
     $coupon->setName('20% Off orders under $100');
     $coupon->setType(PromotionType::percent());
     $coupon->setValue(20);
     $coupon->setMinOrderValue(1000);
     $coupon->setMaxOrderValue(10000);
     $coupon->setReducesTaxSubtotal(false);
     $cartItem = new CartItem();
     $cartItem->setProduct($product);
     $cartItem->setQuantity(1);
     $cart = new Cart();
     $cart->addCoupon($coupon);
     $cart->addCartItem($cartItem);
     $cart->setTaxRate($taxRate);
     $expectedCartTotal = new CartTotal();
     $expectedCartTotal->origSubtotal = 2000;
     $expectedCartTotal->subtotal = 2000;
     $expectedCartTotal->taxSubtotal = 2000;
     $expectedCartTotal->shipping = 0;
     $expectedCartTotal->discount = 400;
     $expectedCartTotal->tax = 160;
     $expectedCartTotal->total = 1760;
     $expectedCartTotal->savings = 400;
     $expectedCartTotal->coupons = [$coupon];
     $expectedCartTotal->taxRate = $taxRate;
     $cartCalculator = new CartCalculator(new Pricing());
     $this->assertEquals($expectedCartTotal, $cartCalculator->getTotal($cart));
 }
 /**
  * @param Product $product
  * @return InventoryTransaction[]
  */
 public function findAllByProduct(Product $product)
 {
     return $this->getQueryBuilder()->select('InventoryTransaction')->from(InventoryTransaction::class, 'InventoryTransaction')->where('InventoryTransaction.product = :productId')->setIdParameter('productId', $product->getId())->getQuery()->getResult();
 }
Example #17
0
 public function addProduct(Product $product)
 {
     $product->addTag($this);
     $this->products[] = $product;
 }
Example #18
0
 public function getSku()
 {
     return $this->product->getSku();
 }