function it_adds_single_item_by_customer(FactoryInterface $orderItemFactory, OrderInterface $order, OrderItemInterface $item, OrderItemQuantityModifierInterface $itemQuantityModifier, ProductInterface $product, SharedStorageInterface $sharedStorage, ProductVariantInterface $variant, ObjectManager $objectManager) { $sharedStorage->get('order')->willReturn($order); $orderItemFactory->createNew()->willReturn($item); $product->getMasterVariant()->willReturn($variant); $product->getPrice()->willReturn(1234); $itemQuantityModifier->modify($item, 1)->shouldBeCalled(); $item->setVariant($variant)->shouldBeCalled(); $item->setUnitPrice(1234)->shouldBeCalled(); $order->addItem($item)->shouldBeCalled(); $objectManager->flush()->shouldBeCalled(); $this->theCustomerBoughtSingle($product); }
/** * @Given /^([^"]+) belongs to ("[^"]+" tax category)$/ */ public function productBelongsToTaxCategory(ProductInterface $product, TaxCategoryInterface $taxCategory) { $product->getMasterVariant()->setTaxCategory($taxCategory); $this->objectManager->flush(); }
/** * @param ProductInterface $product * @param array $data */ private function configureProductPricingCalculator(ProductInterface $product, array $data) { $product->getMasterVariant()->setPricingCalculator($data['pricing calculator']); if (!isset($data['calculator configuration']) || '' === $data['calculator configuration']) { throw new \InvalidArgumentException('You must set chosen calculator configuration'); } $product->getMasterVariant()->setPricingConfiguration($this->getPricingCalculatorConfiguration($data)); }
/** * Adds master variant to product. * * @param ProductInterface $product * @param string $sku */ protected function addMasterVariant(ProductInterface $product, $sku = null) { $variant = $product->getMasterVariant(); $variant->setProduct($product); $variant->setPrice($this->faker->randomNumber(4)); $variant->setSku(null === $sku ? $this->getUniqueSku() : $sku); $variant->setAvailableOn($this->faker->dateTimeThisYear); $variant->setOnHand($this->faker->randomNumber(1)); $variant->setTaxCategory($this->getTaxCategory('Taxable goods')); $productName = explode(' ', $product->getName()); $image = clone $this->getReference('Sylius.Image.' . strtolower($productName[0])); $variant->addImage($image); $this->setReference('Sylius.Variant-' . $this->totalVariants, $variant); ++$this->totalVariants; $product->setMasterVariant($variant); }
/** * @Given the customer bought single :product */ public function theCustomerBoughtSingle(ProductInterface $product) { /** @var OrderInterface $order */ $order = $this->sharedStorage->get('order'); /** @var OrderItemInterface $item */ $item = $this->orderItemFactory->createNew(); $item->setVariant($product->getMasterVariant()); $item->setUnitPrice($product->getPrice()); $this->itemQuantityModifier->modify($item, 1); $order->addItem($item); $this->objectManager->flush(); }
/** * @Then the order item with product :product should not exist */ public function orderItemShouldNotExistInTheRegistry(ProductInterface $product) { $orderItems = $this->orderItemRepository->findBy(['variant' => $product->getMasterVariant()]); expect($orderItems)->toBe([]); }
/** * @Given the customer bought single :product using :coupon coupon */ public function theCustomerBoughtSingleUsing(ProductInterface $product, CouponInterface $coupon) { $order = $this->addSingleProductVariantToOrder($product->getMasterVariant(), $product->getPrice()); $order->setPromotionCoupon($coupon); $this->orderRecalculator->recalculate($order); $this->objectManager->flush(); }
function it_throws_an_exception_if_order_item_still_exist(RepositoryInterface $orderItemRepository, ProductInterface $product, ProductVariantInterface $productVariant, OrderItemInterface $orderItem) { $product->getMasterVariant()->willReturn($productVariant); $orderItemRepository->findBy(['variant' => $productVariant])->willReturn([$orderItem]); $this->shouldThrow(NotEqualException::class)->during('orderItemShouldNotExistInTheRegistry', [$product]); }