1

I'm new to magento 2 and would like to know if it is possible to make a module that generates flags on products with purchase restriction? For example, the product can only be added to the cart when the user is logged in.

0

I'm not sure about your requirement in details. My suggestion is that we can use the Observer event in this case. We catch event checkout_cart_product_add_before on the frontend to prevent non-logged customer adding product to cart.

that generates flags on products with purchase restriction

An easiest way is to create a product attribute.

3
  • Is this capture from the module frontend file I am creating? I don't get it yet, I'm extremely new to Magento Jul 24 '19 at 16:38
  • What I'm thinking of doing is creating a product group that can only be purchased with login. Therefore the flag indicating the restriction Jul 24 '19 at 18:00
  • Khoa, My observer I did like this: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="checkout_cart_product_add_before"> <observer name="access_verification" instance="Lucsfernandes\FlagIndication\Observer\VerificationAccess"/> </event> </config> Is that correct? Jul 24 '19 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.