# How we cannot allow adding to basket based of some availability rules?

**URL:** <https://forum.shopware.com/t/how-we-cannot-allow-adding-to-basket-based-of-some-availability-rules/61740>\
**Category:** Programmierung\
**Created:** [12. September 2019 um 14:54 UTC](https://forum.shopware.com/t/how-we-cannot-allow-adding-to-basket-based-of-some-availability-rules/61740 "2019-09-12T14:54:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SorinSologics2019](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SorinSologics2019](https://forum.shopware.com/u/SorinSologics2019)\
**Post date:** [12. September 2019 um 14:54 UTC](https://forum.shopware.com/t/how-we-cannot-allow-adding-to-basket-based-of-some-availability-rules/61740/1 "2019-09-12T14:54:37Z")

</div>

Hello everybody,

We do not want to allow users to add items to cart if the item is not available based on some custom fields logic and not from twig templates.

We started from the controller function ‘addLineItems’ (Shopware\Storefront\Controller\CartLineItemController) then we go further to cart service:

```
 $cart = $this-\>cartService-\>add($cart, $lineItem, $salesChannelContext);

```

Is it possible to decorate&nbsp;Shopware\Core\Checkout\Cart\SalesChannel\CartService in order to change the ‘add’ function by adding our logic?

Does anyone have an ideea how we can achive this?

Best regards,

Sorin

&nbsp;

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [13. September 2019 um 05:41 UTC](https://forum.shopware.com/t/how-we-cannot-allow-adding-to-basket-based-of-some-availability-rules/61740/2 "2019-09-13T05:41:17Z")

</div>

Hey Sorin,

in the \Shopware\Core\Checkout\Cart\SalesChannel\CartService::add method, an event is dispatched:&nbsp;LineItemAddedEvent  
You could subscribe to this event and check the just added lineItem if it fits your custom logic. If not you could remove it again.

Maybe we should add an additional event right at the beginning of the method, so that the item could completely prevented to be added to the cart.&nbsp;  
If you like, we would appreciate a PR from you on GitHub&nbsp;[Pull requests · shopware/platform · GitHub](https://github.com/shopware/platform/pulls)  
Otherwise you could also create a ticket&nbsp;for that here:&nbsp;[https://issues.shopware.com/](https://issues.shopware.com/)

Best regards from Schöppingen

![cool](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![SorinSologics2019](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@SorinSologics2019](https://forum.shopware.com/u/SorinSologics2019)\
**Post date:** [13. September 2019 um 06:53 UTC](https://forum.shopware.com/t/how-we-cannot-allow-adding-to-basket-based-of-some-availability-rules/61740/3 "2019-09-13T06:53:50Z")

</div>

Hello Michael,

Thank you for your answer. I’m pretty sure that your solution will work on current implementation, but will be great if an event

will be added before adding an item to cart. I’ll place a ticket on&nbsp;[https://issues.shopware.com/](https://issues.shopware.com/)

&nbsp;

Best regards,

Sorin

---

<div class="post-metadata">

**Author:** ![Kairalen](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Kairalen](https://forum.shopware.com/u/Kairalen)\
**Post date:** [22. April 2020 um 16:50 UTC](https://forum.shopware.com/t/how-we-cannot-allow-adding-to-basket-based-of-some-availability-rules/61740/4 "2020-04-22T16:50:20Z")

</div>

Hello Sorin,

I faced a similar problem, please tell me if you managed to solve it? And if you did, how?

Best regards,

Anastasia

---

<div class="post-metadata">

**Author:** ![WernerBu](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@WernerBu](https://forum.shopware.com/u/WernerBu)\
**Post date:** [23. April 2020 um 07:06 UTC](https://forum.shopware.com/t/how-we-cannot-allow-adding-to-basket-based-of-some-availability-rules/61740/5 "2020-04-23T07:06:49Z")

</div>

Hi,

that would be very helpfull for us, if an event will be dispatched before adding an item to the cart.

But i cannot find the ticket?

Thanks and best regards,

Werner.
