Score:0

Shipping configuration for x items or more

br flag

Using Drupal9 and Commerce2 I'm trying to configure shipping for a specific variation type : tires.

If you order one or 2 tires, you must pick them up on site. if you order 4 or more, they can be shipped for free. there is no intermediate possibility, no possibility of shipping with postage if you buy less than 4.

So I configured the type of variation by not checking the "shippable" box.

Now in a CartEventSubscriber, I would like to be able to change the value of "shippable" from the moment there are 4 items of this type (or more) in the cart.

When I add a product to the cart, I can't find any trace of the shippable property in the item or in the variation...

public function addToCart(CartEntityAddEvent $event) {
  $order_item = $event -> getOrderItem();
  $variation = $order_item -> getPurchasedEntity();
        
  dpm($order_item);
  dpm($variation);
}

Does anyone have an idea how to achieve the result I need?

Thanks in advance for your answers.

No Sssweat avatar
ua flag
Have a look at https://git.drupalcode.org/project/commerce_shipping/-/blob/8.x-2.x/src/EventSubscriber/CartSubscriber.php might point you in the right direction.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.