New answers tagged

1

Try below event Magento 2 :- <event name="customer_save_after_data_object"> <observer name="customer_save_after_observer" instance="Vendor\Sales\Observer\CustomereditPost" /> </event> Magento 1 : - <config> <adminhtml> <events> <adminhtml_customer_save_after> <...


0

Since you should not use the object manager a better way would be to use the checkout session: use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Psr\Log\LoggerInterface; class DisablePayment implements ObserverInterface { protected $_logger; protected $checkoutSession; public function __construct( \Magento\...


0

This is what worked: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cartObj = $objectManager->get('\Magento\Checkout\Model\Cart'); $subTotal = $cartObj->getQuote()->getSubtotal(); //Current Cart Subtotal $grandTotal = $cartObj->getQuote()->getGrandTotal(); //Cart Grand total Then I just used this - $total = $...


0

As per your requirements, I've found the three customer actions (Edit Account Information, Change Password, and Edit Address) you need observer event for. You can add below customer observer events for your requirements: Edit Account Information: You can use customer_save_after_data_object event. Change Password: You can use ...


0

Please try with below module to reindex manually from admin : https://github.com/magepal/magento2-reindex or programmatically try with below code : protected $_indexerFactory; /** * @var \Magento\Indexer\Model\Indexer\CollectionFactory */ protected $_indexerCollectionFactory; public function __construct( \Magento\Indexer\Model\IndexerFactory $...


1

You can check/compare customer's old password and updated password value by below code. <?php namespace Vendor\Magento\Observer; use Magento\Framework\Event\ObserverInterface; class CustomerLogin implements ObserverInterface { protected $encryptor; protected $_messageManager; protected $objectManager; public function __construct( ...


1

You can use customer_login event observer to get customer group after login and then logout the customer in observer app/code/Vendor/Module/etc/events.xml <?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="...


0

You have the syntax issue. class CheckProduct implements ObserverInterface { protected $_logger; protected $_storeManager; protected $messageManager; protected $productRepository; protected $_resultPageFactory; public function __construct( \Psr\Log\LoggerInterface $logger, \Magento\Store\Model\...


0

You can include the quote as a dependency in your mixin (or new component) and subscribe on the shippingAddress like this: define([ 'ko', 'uiElement', 'jquery', 'Magento_Checkout/js/model/quote', 'domReady!', ], function (ko, Component, $, quote) { 'use strict'; return Component.extend({ initialize: function () { ...


2

You can use customer_register_success event for create account event in your custom module. Also, below is the reference link for all the events list available in Magento 2. https://www.rakeshjesadiya.com/list-of-all-events-in-magento-2/ Hope it helps!!!


0

There is not specific event for customer update you can try with below event adminhtml_customer_prepare_save


0

Step 1: Dispatch event In Magento 2, you can dispatch the event from any place: controller, model, block, data… We will create an event from controller file. File directory: app/code/vendor/module_name/Controller/Index/Index.php <?php namespace Vendor\Module_name\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { ...


0

You simply can't observe that. Magento reads that on the fly each time (crazy)


0

Try below code to get old and new data: foreach ($compareArray as $value) { $old = $product->getOrigData($value); $new = $product->getData($value); if ($old !== $new) { // $event .= "CHANGE:- $value $old=>$new"; $logs = [ 'old_value' => $old, ...


0

First, to add custom field in quote and order table and save your data into quote table. after creating file Vendor\Extension\etc\events.xml <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="...


0

magento 2 order status change event & sales_order_save_after observer https://community.magento.com/t5/Welcome-to-the-Magento-Community/magento-2-order-status-change-event-amp-sales-order-save-after/m-p/141522/highlight/true#M6425


0

My error was the way to get $customer object. This worked for me $customer = $observer->getCustomerDataObject(); $customer_id = $customer->getId();


0

The page cache process method in vendor/magento/framework/App/PageCache/Kernel.php clears the set-cookie header You'll need to find an event that fires after this to set a cookie


0

If you want to change or filter current configuration value, use below way with event admin_system_config_changed_section_{$section} For example, my system.xml like and I want to filter faq_url value at the time of saving the config. <section id="faqtab" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <...


2

You can use sales_order_place_before event before placing the order. Also, for getting shipping description for the order, you can use below code in your observer. $order = $observer->getEvent()->getOrder(); echo $order->getShippingDescription(); If you want shipping method data, then you can use below code $shipping = $order->...


2

In magento1 try to do with this event sales_order_place_before which is work with before place order. and put in config.xml <sales_order_place_before> <observers> <Gta_KolupadiRestrict_Model_Observer> <type>singleton</type> <class>gta_kolupadiRestrict/...


2

How to do an action if an order is placed by a customer You have 2 events you might use (there might be others). sales_order_place_before is dispatched before the order is placed. sales_order_place_after is dispatched after the order is placed. You can create an observer for one of those events. You will find here a tutorial on how to create observers. You ...


2

The event before placing order is “sales_order_place_before“


0

Step 1 : Create custom order attribute. Create a custom module and create a Mysql installer file in your module. {/app/code/local/namespace/modulename/sql/module_setup/mysql4-install-1.1.php}. Before this make sure you have added all resource model related information in etc/config.xml. Put the content in the file. <?php $installer = $this; $installer-&...


0

Try controller_front_send_response_before event instead - it works fine on cached CMS pages. According to the nearest comment in the code - "This event gives possibility to launch something before sending output (allow cookie setting)".


0

Try controller_front_send_response_before event instead. Actually there are no other events fired on all pages including CMS without cache issues. So there is no choice


3

Try below code in your observer, it'll work for you. public function checkproductinorder($Observer) { $order = $Observer->getEvent()->getOrder(); $items = $order->getAllItems(); $skus = array('600','800'); //product SKUs $skuList = array(); foreach ($items as $item) { if(in_array($item->getSku(), $skus)) { ...


2

Try this code public function checkproductinorder($Observer) { $order = $Observer->getEvent()->getOrder(); $items = $order->getAllItems(); $skus = array(); foreach ($items as $item) { if($item->getSku() == '600' || $item->getSku() == '800') { $skus[] = $item->getSku(); } } Mage::...


0

Check the code below for simple add customer comment to order via observer: // get the last order $lastOrderId = $this->_getOnepage()->getCheckout()->getLastOrderId(); $order = Mage::getModel('sales/order')->load($lastOrderId); // Add the comment and save the order (last parameter will determine if comment will be sent to customer) $order->...


0

You can use the below code in your observer to add order comment: $comment = "Comment to be added in the order"; $order->addStatusHistoryComment($comment) ->setIsVisibleOnFront(false) ->setIsCustomerNotified(false); $order->save(); Or you can use below free extension you can use for adding order comments on the checkout ...


0

You have to remove the item and add a new one with the updated price : //get the product from the observer $product = $observer->getEvent()->getData('product'); //get the item just added $item = $observer->getEvent()->getData('quote_item'); //define the new price $yourNewPrice = 100; //get the current store $storeId = $this->_storeManager-...


1

Please try this: foreach($items as $item) { $sku = $item->getSku(); $name= $item->getName(); $qty = $item->getQtyOrdered(); $price = $item->getPrice(); $shipping_state = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->...


0

Was able to grab tracking info using the event sales_order_shipment_save_after and the following in my observer: $shipment = $observer->getEvent()->getShipment(); foreach ($shipment->getAllTracks() as $track) { $tracking = $track; } And as it turns out, this event / observer was actually being called by the ShipStation API however the shipment ...


2

I've saved the custom attribute value to the product with the below code. class FilterProduct implements ObserverInterface { /** * @var \Magento\ConfigurableProduct\Model\Product\Type\ConfigurableFactory */ protected $configurableProductProductTypeConfigurableFactory; public function __construct( \Magento\ConfigurableProduct\...


2

Both are different events. sales_quote_add_item When item added to the cart this event triggered. _merge_before Event is triggered when quotes are merged. Example When guest user login if he had an item in the cart then both quotes are merged.


0

Is there a chance throwing an exception would halt execution? public function hookToAddToCartBefore($observer) { $request = $observer->getEvent()->getRequest()->getParams(); $product = Mage::getModel('catalog/product')->load($request['product']); if($product->getSku != "TEST"){ //Display message error Mage::...


Top 50 recent answers are included