I've created a custom widget with a parameter to select an existing category and the widget displays the products in this category. This widget works as expected.

Now I want to add a new check on reorder for when the customer reorders an order with a product from the widget. I'm able to intercept the reorder action, but I don't know how to check if the product comes from the widget. What I mean is:

  • if it was system config instead of a widget, I could simply get the category from the system config and use this value to check the product.. something like this:
$categoryId = $this->scopeConfig->getValue($field, ScopeInterface::SCOPE_STORE, $storeId); // get the category id from stores > configuration
if(in_array($categoryId, $quoteItem->getProduct()->getCategoryIds()) {
   // this product comes from my category. I can do my stuff with it

In my case, though, $categoryId is not set in the system.xml file but in the widget.xml. I can successfully get the widget parameter in the widget block and the widget template, but how can I get the parameter in the observer/controller/plugin that I need to manipulate the reorder action? Something like this:

$categoryId = $this->widget->getParam('category_id');
// same code as before

The only thing I was able to come up with is to set/get the parameter in the session, but I hoped there was a better solution than messing up with the registry

Your Answer

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

Browse other questions tagged or ask your own question.