Showing results for 
Search instead for 
Did you mean: 

Magento EE GiftRegistry - Edit Fulfilled Qty

Magento EE GiftRegistry - Edit Fulfilled Qty

My team would like to be able to edit the fulfilled quantity on any given gift registry item, in Magento 2 EE. This is my first foray into Magento modification (and I did not use Magento 1.x), so I'm trying to find my way.

I have identified the following steps, which (when performed on the core code) allow this to happen:

1. Create ...Block\Adminhtml\Widget\Grid\Column\Renderer\Fulfilled.php , similar to Qty.php. This will allow the Fulfilled column to contain a text box.
2. Use that Fulfilled.php as the renderer for 'qty_fulfilled' in the _prepareColumns() method in ...Block\Adminhtml\Customer\Edit\Items.php.
3. Modify the execute() method in ...Controller\Adminhtml\Giftregistry\Customer\Update.php to call $model->setQtyFulfilled($data['qty_fulfilled']) (immediately after it calls $model->setQty($data['qty']))

I understand that the proper practice is not to modify core modules, but to instead insert these changes via an extension. However, I'm running into the following issues:

1. I'm not sure how to best go about extending the _prepareColumns() method, since it is protected and I cannot use a plugin. The reading I've done indicates I need to find a public method at some point where I can attach a plugin and modify the column list, but I've not found where to do this yet.

2. I've been trying to modify the execute() method via a plugin, but I'm not sure if it's the right approach. I thought I might use an aroundExecute plugin, and simply replace the core method functionality - since where I want to add that one call is in the middle of the method, nested inside a try/catch and a foreach loop.
I tried using aroundExecute() as a plugin, and just pasting in the code from execute(). I also tried replacing all instances of $this with the passed-in $subject (I don't know if that is correct or not). I'm not trying to change any functionality yet - just get it into a plugin so that I may edit it. This resulted in 500 errors with no message. I am in developer mode, with display_errors On and error_reporting at E_ALL | E_STRICT. Just calling $proceed() alone in the plugin works as expected.

Any suggestions or pointers would be really helpful, thanks!


Re: Magento EE GiftRegistry - Edit Fulfilled Qty

"since it is protected and I cannot use a plugin"


You can attach a plugin to a protected method by inherit the plugin class from the modifiable class.

Oh, it is wrong.

Re: Magento EE GiftRegistry - Edit Fulfilled Qty

Thanks a lot for the response! I thought I understood, but apparently not - I'm sure I'm probably doing several things wrong. I tried having my plugin class inherit from the class I am modifying. This is my plugin code - I thought I would start by simply trying to add a 'Test' column to the grid, to see if I could get the plugin affecting the _prepareColumns method. I'm not getting any errors, but it also doesn't appear to be doing anything.



namespace Myvendorname\GiftRegistryFulfilledEdit\Plugin;

class FulfilledTextBox extends \Magento\GiftRegistry\Block\Adminhtml\Customer\Edit\Items

    public function around_prepareColumns(\Magento\GiftRegistry\Block\Adminhtml\Customer\Edit\Items $subject, \Closure $proceed)
        $subject->addColumn('test', ['header' => __('TEST'), 'index' => 'test', 'width' => '200px']);

        return $proceed();


Re: Magento EE GiftRegistry - Edit Fulfilled Qty

Oh, sorry, I gave a wrong answer.

Looks like the only way to change the protected "_prepareColumns" method is to make a subclass of the Fulfilled class and override the method.

You can use a "preference" to replace the standard cllass with a new one:

It has a drawback: if another extension will try to set a preference for the same class too, it will be a conflict.

So the better would be to find a place where the Fulfilled class is instantiated and replace the standard class with yours.


Re: Magento EE GiftRegistry - Edit Fulfilled Qty

Alright, I think I follow that. The Fulfilled class is the plugin class that I made - I'm trying to modify the Items class. Thanks for the help, I'll keep hunting for a place to do a replacement.


I'd like to leave the thread open for a bit, to see if anyone has further suggestions, particularly about modifying the execute method in ...Giftregistry\Customer\Update.php.


Thanks again for the help!