What are the Slack Archives?

Itโ€™s a history of our time together in the Slack Community! Thereโ€™s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you wonโ€™t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hi all, I added a CartPreCheck plugin to check for the availability of a product that I get by reque

ULW0Z4150
ULW0Z4150 Posts: 69 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

Hi all,
I added a CartPreCheck plugin to check for the availability of a product that I get by requesting the stock of the product from a NAVConnect. I managed to get an error message when the check for availability fails. But the product is still added to the cart. I debugged through AvailabilityCartConnector/Business/Cart/CheckCartAvailability.php which determines isSellable but it is unclear to me where the product is actually excluded from being added to the cart. Maybe someone can help me where this takes place?

Comments

  • Hi David! Are you talking about
    \Spryker\Zed\CartExtension\Dependency\Plugin\CartPreCheckPluginInterface this plugin stack?

  • ULW0Z4150
    ULW0Z4150 Posts: 69 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Yes exactly

  • Specification says:

    Should return CartPreCheckResponseTransfer where error messages set and flag that check failed.
    
  • Have you set ->setIsSuccess(false) ?

  • ULW0Z4150
    ULW0Z4150 Posts: 69 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Yes Iโ€™m checking the condition for the product being available, if it isnโ€™t available I set success to false and add the message. It looks something like this:

    $cartPreCheckResponseTransfer->setIsSuccess(false);
                    $errorMessage = (new MessageTransfer())
         ->setValue(static::CART_PRE_CHECK_NAVCONNECT_NOT_AVAILABLE_TRANSLATION_KEY)
                        ->setParameters(['%sku%' => $itemTransfer->getSku()]);
                    $cartPreCheckResponseTransfer->addMessage($errorMessage);
    
  • ULW0Z4150
    ULW0Z4150 Posts: 69 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    The message appears when the condition is met but the element still appears in the cart and im unsure where the decision is made if it is added to the cart or not

  • vendor/spryker/spryker/Bundles/Cart/src/Spryker/Zed/Cart/Business/Model/Operation.php:206

  • Check this. Maybe it will help

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    With this particular plugin stack I had the experience that plugins included later can override the negative response of the previous plugin. Please check this is not happening in you case

  • ULW0Z4150
    ULW0Z4150 Posts: 69 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Thanks for the advice, Iโ€™ll give both of those suggestions a try and get back to you ๐Ÿ‘

  • giovanni.piemontese
    giovanni.piemontese Spryker Solution Partner Posts: 871 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Hi, you have maybe to implement the TerminationAwareCartPreCheckPluginInterface and implements the method public function terminateOnFailure() with return true.