Hello, I’ve been following the documentation on how to create an Order programmatically. I’ve stumbled onto a problem when trying to create an Order with a Product that is on Promotion. From what I understood simulating the “adding of a product to a cart” is the same as creating an order in the CART state, so this was the way to go for me. I created a product that has one variant only with a price of 200.00USD. I later created a Promotion with a Rule of the type “Contains a product” and selected the base product of the variant. I added then an action of type “Order percentage discount” of 30%, enabled the promotion for all the channels and enabled coupons and specified a valid date range.
In code I wrote this:
$product = $this->container->get('sylius.repository.product')->findOneBy(['code' => $pid]); $variant = $product->getVariants()->first(); $orderItem = $this->container->get('sylius.factory.order_item')->createNew(); $orderItem->setVariant($variant); $this->container->get('sylius.order_item_quantity_modifier')->modify($orderItem, 3); $order = $factory->createNew(); $order->setState( OrderInterface::STATE_CART ); $order->setLocaleCode($localeCode); $order->setChannel($channel); $order->setCurrencyCode($currencyCode); $order->setCustomer($customer); $order->addItem( $orderItem ); $this->container->get('sylius.order_processing.order_processor')->process($order); var_dump( $order->getTotal()); die();
being $pid my Product code.
The output I got is:
from which my understanding is that the order correctly calculates 3 order items of value 200.00USD each, but the problem is that the promotional discount hasn’t been applied.
Any ideas on what’s missing here?
Thanks in advance …