Order beforeSave plugin throws TypeErrormagento Plugin is not working on CollectRates method shipping method classMagento 2: Plugin class does not existHow to override contact us post action using plugin Magento 2Magento 2 Front controller reached 100 router match iterations issueMagento 2.3 Inject helper into controller object type error?Magento2 REST API get all customers details“Area code is not set” in var/logwhen click on place order then paypal showing error in Magento2Magento2 Get Order API data in custom sectionMagento2.3.1 issue with payment via authorized.net
Infeasibility in mathematical optimization models
How to mark beverage cans in a cooler for a blind person?
Why should public servants be apolitical?
Is there a loss of quality when converting RGB to HEX?
Secure my password from unsafe servers
Replace data between quotes in a file
Looking for a new job because of relocation - is it okay to tell the real reason?
Best gun to modify into a monsterhunter weapon?
Why couldn't soldiers sight their own weapons without officers' orders?
Acceptable to cut steak before searing?
Why did the RAAF procure the F/A-18 despite being purpose-built for carriers?
Use of "When" in present vs "whenever"
What happen if I gain the control of aura that enchants an opponent's creature? Would the aura stay attached?
How to query data in backups?
How quickly could a country build a tall concrete wall around a city?
In Pokémon Go, why does one of my Pikachu have an option to evolve, but another one doesn't?
Why are physicists so interested in irreps if in their non-block-diagonal form they mix all components of a vector?
During the Space Shuttle Columbia Disaster of 2003, Why Did The Flight Director Say, "Lock the doors."?
Can an SPI slave start a transmission in full-duplex mode?
Can I call myself an assistant professor without a PhD
Dereferencing a pointer in a for loop initializer creates a seg fault
In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?
How does The Fools Guild make its money?
Dropdowns & Chevrons for Right to Left languages
Order beforeSave plugin throws TypeError
magento Plugin is not working on CollectRates method shipping method classMagento 2: Plugin class does not existHow to override contact us post action using plugin Magento 2Magento 2 Front controller reached 100 router match iterations issueMagento 2.3 Inject helper into controller object type error?Magento2 REST API get all customers details“Area code is not set” in var/logwhen click on place order then paypal showing error in Magento2Magento2 Get Order API data in custom sectionMagento2.3.1 issue with payment via authorized.net
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I've built a plugin that catches the order beforeSave event in order to add some extra data to the an order attribute. The problem is that when this plugin fires it causes an error:
Uncaught TypeError: Argument 1 passed to MagentoSalesModelOrderRepository::save() must implement interface MagentoSalesApiDataOrderInterface, string given, called in /var/www/html/vendor/magento/framework/Interception/Interceptor.php on line 58 and defined in /var/www/html/vendor/magento/module-sales/Model/OrderRepository.php:156
Stack trace:
#0 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoSalesModelOrderRepository->save('sales_order', 'order', NULL, NULL, NULL, NULL, Array, NULL, NULL, Array, true, 'order', Object(MagentoStoreModelStoreManager), Object(MagentoSalesModelOrderConfig), Object(MagentoCatalogModelProductRepositoryInterceptor), Object(MagentoCatalogModelResourceModelProductCollectionFactory), Object(MagentoSalesModelResourceModelOrderItemCollectionFactory), Object(MagentoCatalogModelProductVisibility), Object(MagentoSalesModelServiceInvoiceService), Object(MagentoDirectoryModelCurrencyF"
I've cut down my plugin so it does absolutely nothing other than return the same object in gets at the start and I'm still getting this same issue. For example;
class OrderPlugin
{
protected $_logger;
protected $_orderApi;
protected $_orderAttributeFactory;
protected $_orderExtensionFactory;
public function __construct(PsrLogLoggerInterface $logger, Data $helper, MyModuleShipstationModelOrderAttributeFactory $orderAttributeFactory, OrderExtensionFactory $orderExtensionFactory)
$this->_logger = $logger;
$this->helper = $helper;
$this->_orderAttributeFactory = $orderAttributeFactory;
$this->_orderExtensionFactory = $orderExtensionFactory;
public function beforeSave(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
//$resultOrder = $this->saveFarmisonOrderIDAttribute($resultOrder);
return $order;
my di.xml looks like;
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_Shipstation::orderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_Shipstation::deliverydatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
If I totally comment out my beforeSave method then the save works correctly as expected/
magento2 magento2.3 plugin dependency-injection before-plugin
add a comment |
I've built a plugin that catches the order beforeSave event in order to add some extra data to the an order attribute. The problem is that when this plugin fires it causes an error:
Uncaught TypeError: Argument 1 passed to MagentoSalesModelOrderRepository::save() must implement interface MagentoSalesApiDataOrderInterface, string given, called in /var/www/html/vendor/magento/framework/Interception/Interceptor.php on line 58 and defined in /var/www/html/vendor/magento/module-sales/Model/OrderRepository.php:156
Stack trace:
#0 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoSalesModelOrderRepository->save('sales_order', 'order', NULL, NULL, NULL, NULL, Array, NULL, NULL, Array, true, 'order', Object(MagentoStoreModelStoreManager), Object(MagentoSalesModelOrderConfig), Object(MagentoCatalogModelProductRepositoryInterceptor), Object(MagentoCatalogModelResourceModelProductCollectionFactory), Object(MagentoSalesModelResourceModelOrderItemCollectionFactory), Object(MagentoCatalogModelProductVisibility), Object(MagentoSalesModelServiceInvoiceService), Object(MagentoDirectoryModelCurrencyF"
I've cut down my plugin so it does absolutely nothing other than return the same object in gets at the start and I'm still getting this same issue. For example;
class OrderPlugin
{
protected $_logger;
protected $_orderApi;
protected $_orderAttributeFactory;
protected $_orderExtensionFactory;
public function __construct(PsrLogLoggerInterface $logger, Data $helper, MyModuleShipstationModelOrderAttributeFactory $orderAttributeFactory, OrderExtensionFactory $orderExtensionFactory)
$this->_logger = $logger;
$this->helper = $helper;
$this->_orderAttributeFactory = $orderAttributeFactory;
$this->_orderExtensionFactory = $orderExtensionFactory;
public function beforeSave(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
//$resultOrder = $this->saveFarmisonOrderIDAttribute($resultOrder);
return $order;
my di.xml looks like;
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_Shipstation::orderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_Shipstation::deliverydatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
If I totally comment out my beforeSave method then the save works correctly as expected/
magento2 magento2.3 plugin dependency-injection before-plugin
add a comment |
I've built a plugin that catches the order beforeSave event in order to add some extra data to the an order attribute. The problem is that when this plugin fires it causes an error:
Uncaught TypeError: Argument 1 passed to MagentoSalesModelOrderRepository::save() must implement interface MagentoSalesApiDataOrderInterface, string given, called in /var/www/html/vendor/magento/framework/Interception/Interceptor.php on line 58 and defined in /var/www/html/vendor/magento/module-sales/Model/OrderRepository.php:156
Stack trace:
#0 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoSalesModelOrderRepository->save('sales_order', 'order', NULL, NULL, NULL, NULL, Array, NULL, NULL, Array, true, 'order', Object(MagentoStoreModelStoreManager), Object(MagentoSalesModelOrderConfig), Object(MagentoCatalogModelProductRepositoryInterceptor), Object(MagentoCatalogModelResourceModelProductCollectionFactory), Object(MagentoSalesModelResourceModelOrderItemCollectionFactory), Object(MagentoCatalogModelProductVisibility), Object(MagentoSalesModelServiceInvoiceService), Object(MagentoDirectoryModelCurrencyF"
I've cut down my plugin so it does absolutely nothing other than return the same object in gets at the start and I'm still getting this same issue. For example;
class OrderPlugin
{
protected $_logger;
protected $_orderApi;
protected $_orderAttributeFactory;
protected $_orderExtensionFactory;
public function __construct(PsrLogLoggerInterface $logger, Data $helper, MyModuleShipstationModelOrderAttributeFactory $orderAttributeFactory, OrderExtensionFactory $orderExtensionFactory)
$this->_logger = $logger;
$this->helper = $helper;
$this->_orderAttributeFactory = $orderAttributeFactory;
$this->_orderExtensionFactory = $orderExtensionFactory;
public function beforeSave(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
//$resultOrder = $this->saveFarmisonOrderIDAttribute($resultOrder);
return $order;
my di.xml looks like;
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_Shipstation::orderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_Shipstation::deliverydatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
If I totally comment out my beforeSave method then the save works correctly as expected/
magento2 magento2.3 plugin dependency-injection before-plugin
I've built a plugin that catches the order beforeSave event in order to add some extra data to the an order attribute. The problem is that when this plugin fires it causes an error:
Uncaught TypeError: Argument 1 passed to MagentoSalesModelOrderRepository::save() must implement interface MagentoSalesApiDataOrderInterface, string given, called in /var/www/html/vendor/magento/framework/Interception/Interceptor.php on line 58 and defined in /var/www/html/vendor/magento/module-sales/Model/OrderRepository.php:156
Stack trace:
#0 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoSalesModelOrderRepository->save('sales_order', 'order', NULL, NULL, NULL, NULL, Array, NULL, NULL, Array, true, 'order', Object(MagentoStoreModelStoreManager), Object(MagentoSalesModelOrderConfig), Object(MagentoCatalogModelProductRepositoryInterceptor), Object(MagentoCatalogModelResourceModelProductCollectionFactory), Object(MagentoSalesModelResourceModelOrderItemCollectionFactory), Object(MagentoCatalogModelProductVisibility), Object(MagentoSalesModelServiceInvoiceService), Object(MagentoDirectoryModelCurrencyF"
I've cut down my plugin so it does absolutely nothing other than return the same object in gets at the start and I'm still getting this same issue. For example;
class OrderPlugin
{
protected $_logger;
protected $_orderApi;
protected $_orderAttributeFactory;
protected $_orderExtensionFactory;
public function __construct(PsrLogLoggerInterface $logger, Data $helper, MyModuleShipstationModelOrderAttributeFactory $orderAttributeFactory, OrderExtensionFactory $orderExtensionFactory)
$this->_logger = $logger;
$this->helper = $helper;
$this->_orderAttributeFactory = $orderAttributeFactory;
$this->_orderExtensionFactory = $orderExtensionFactory;
public function beforeSave(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
//$resultOrder = $this->saveFarmisonOrderIDAttribute($resultOrder);
return $order;
my di.xml looks like;
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_Shipstation::orderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_Shipstation::deliverydatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
If I totally comment out my beforeSave method then the save works correctly as expected/
magento2 magento2.3 plugin dependency-injection before-plugin
magento2 magento2.3 plugin dependency-injection before-plugin
asked Jul 29 at 23:18
MatthewMatthew
1135 bronze badges
1135 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can try this way,
app/code/Vendor/Module/etc/di.xml
<type name="MagentoSalesModelOrder">
<plugin name="Plugin Name" type="VendorModulePluginOrder" sortOrder="10" disabled="false"/>
</type>
app/code/Vendor/Module/Plugin/Order.php
public function beforeSave(MagentoSalesModelOrder $subject)
$subject->getData()
// this is your order Data before saving it
Hope it Helps.
add a comment |
Change di.xml
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_OrderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_DeliveryDatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
Can you explain why?
– Matthew
Jul 30 at 11:09
add a comment |
The solution I found was to simply remove the return from the function. Setting that value I wanted on the order object was enough and simply removing the return allowed the code to run as expected.
public function beforeSave(MagentoSalesModelOrderRepository $subject, $resultOrder)
$this->saveOrderIDAttribute($resultOrder);
What I don't know is why beforeSave doesn't like having the Order object returned. Where as afterGet works exactly as I would expect and accepts the order object from the return.
public function afterGet(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
$order = $this->getOrderIDAttribute($order);
return $order;
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f283724%2forder-beforesave-plugin-throws-typeerror%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try this way,
app/code/Vendor/Module/etc/di.xml
<type name="MagentoSalesModelOrder">
<plugin name="Plugin Name" type="VendorModulePluginOrder" sortOrder="10" disabled="false"/>
</type>
app/code/Vendor/Module/Plugin/Order.php
public function beforeSave(MagentoSalesModelOrder $subject)
$subject->getData()
// this is your order Data before saving it
Hope it Helps.
add a comment |
You can try this way,
app/code/Vendor/Module/etc/di.xml
<type name="MagentoSalesModelOrder">
<plugin name="Plugin Name" type="VendorModulePluginOrder" sortOrder="10" disabled="false"/>
</type>
app/code/Vendor/Module/Plugin/Order.php
public function beforeSave(MagentoSalesModelOrder $subject)
$subject->getData()
// this is your order Data before saving it
Hope it Helps.
add a comment |
You can try this way,
app/code/Vendor/Module/etc/di.xml
<type name="MagentoSalesModelOrder">
<plugin name="Plugin Name" type="VendorModulePluginOrder" sortOrder="10" disabled="false"/>
</type>
app/code/Vendor/Module/Plugin/Order.php
public function beforeSave(MagentoSalesModelOrder $subject)
$subject->getData()
// this is your order Data before saving it
Hope it Helps.
You can try this way,
app/code/Vendor/Module/etc/di.xml
<type name="MagentoSalesModelOrder">
<plugin name="Plugin Name" type="VendorModulePluginOrder" sortOrder="10" disabled="false"/>
</type>
app/code/Vendor/Module/Plugin/Order.php
public function beforeSave(MagentoSalesModelOrder $subject)
$subject->getData()
// this is your order Data before saving it
Hope it Helps.
answered Jul 30 at 5:31
Mohit RaneMohit Rane
1,21118 bronze badges
1,21118 bronze badges
add a comment |
add a comment |
Change di.xml
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_OrderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_DeliveryDatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
Can you explain why?
– Matthew
Jul 30 at 11:09
add a comment |
Change di.xml
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_OrderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_DeliveryDatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
Can you explain why?
– Matthew
Jul 30 at 11:09
add a comment |
Change di.xml
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_OrderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_DeliveryDatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
Change di.xml
<type name="MagentoSalesApiOrderRepositoryInterface">
<plugin name="MyModule_OrderPlugin" type="MyModuleShipstationPluginOrderPlugin" />
<plugin name="MyModule_DeliveryDatePlugin" type="MyModuleShipstationPluginDeliveryDatePlugin" />
</type>
answered Jul 30 at 10:52
MageCoderMageCoder
759 bronze badges
759 bronze badges
Can you explain why?
– Matthew
Jul 30 at 11:09
add a comment |
Can you explain why?
– Matthew
Jul 30 at 11:09
Can you explain why?
– Matthew
Jul 30 at 11:09
Can you explain why?
– Matthew
Jul 30 at 11:09
add a comment |
The solution I found was to simply remove the return from the function. Setting that value I wanted on the order object was enough and simply removing the return allowed the code to run as expected.
public function beforeSave(MagentoSalesModelOrderRepository $subject, $resultOrder)
$this->saveOrderIDAttribute($resultOrder);
What I don't know is why beforeSave doesn't like having the Order object returned. Where as afterGet works exactly as I would expect and accepts the order object from the return.
public function afterGet(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
$order = $this->getOrderIDAttribute($order);
return $order;
add a comment |
The solution I found was to simply remove the return from the function. Setting that value I wanted on the order object was enough and simply removing the return allowed the code to run as expected.
public function beforeSave(MagentoSalesModelOrderRepository $subject, $resultOrder)
$this->saveOrderIDAttribute($resultOrder);
What I don't know is why beforeSave doesn't like having the Order object returned. Where as afterGet works exactly as I would expect and accepts the order object from the return.
public function afterGet(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
$order = $this->getOrderIDAttribute($order);
return $order;
add a comment |
The solution I found was to simply remove the return from the function. Setting that value I wanted on the order object was enough and simply removing the return allowed the code to run as expected.
public function beforeSave(MagentoSalesModelOrderRepository $subject, $resultOrder)
$this->saveOrderIDAttribute($resultOrder);
What I don't know is why beforeSave doesn't like having the Order object returned. Where as afterGet works exactly as I would expect and accepts the order object from the return.
public function afterGet(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
$order = $this->getOrderIDAttribute($order);
return $order;
The solution I found was to simply remove the return from the function. Setting that value I wanted on the order object was enough and simply removing the return allowed the code to run as expected.
public function beforeSave(MagentoSalesModelOrderRepository $subject, $resultOrder)
$this->saveOrderIDAttribute($resultOrder);
What I don't know is why beforeSave doesn't like having the Order object returned. Where as afterGet works exactly as I would expect and accepts the order object from the return.
public function afterGet(MagentoSalesApiOrderRepositoryInterface $subject, MagentoSalesApiDataOrderInterface $order)
$order = $this->getOrderIDAttribute($order);
return $order;
answered Jul 30 at 20:23
MatthewMatthew
1135 bronze badges
1135 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f283724%2forder-beforesave-plugin-throws-typeerror%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown