Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
3

Logically I don't see any benefit of creating multiple classes for same functionality. Moreover having same class it will help in code redundancy, upgrading and also debugging. In case of Plugin you should have different class defined even if the functionality is same . But in case of observer it would be better if you use the same class in my opinion.


2

In the Temando_Shipping module there is the method Temando\Shipping\Plugin\Sales\OrderRepositoryPlugin::afterSave. In the comment of this method there is this /** * Manifest order at Temando platform. * * Observers don't work: * - `sales_order_save_commit_after` is no longer triggered in guest checkout * - `sales_order_save_after` does not have related ...


2

You will have an entity_id only after the object has been saved to database, therefore the earliest event to get that value is sales_order_creditmemo_safe_after. But an increment_id can be generated in an earlier phase - you just have to generate it by yourself. Automatically the increment_id is generated in the save bevore process of the ressource model ...


2

You can try below code for get order increment id in observer. $order = $observer->getEvent()->getOrder(); $incrementId = $order->getIncrementId();


2

I think in you can mock your Observer class with getData method i.e $eventObserverMock = $this->getMockBuilder(Observer::class) ->setMethods(['getData']) ->disableOriginalConstructor() ->getMock(); Now getData method is mock so you can set the some value with return type which you want true or false ...


2

As per your requirement, you have mentioned that the functionality of the observer has nothing to do with the observer argument and is independent. In this case, according to me, the best solution is to create and call a single observer file and function. The main benefit of it is that if in future there are some changes, change needs to be in one single ...


1

Depends how you look at it. Magento is (MySQL) transactional which means things are getting queued whilst tables are locked. They are then processed in a first come first serves basis when locks are released. Observers would also work on this basis. I don't believe community edition has anything more complex then that. I've read about enterprise edition ...


1

Save Product Using ProductRepositoryInterface :- $option = $this->_objectManager->create(\Magento\Catalog\Model\Product\Option::class) ->setProductId($_product->getId()) ->setStoreId($_product->getStoreId()) ->addData($arrayOption); $option->save(); $product->addOption($option); $productRepo = $...


1

You can try using a Product Repository Magento\Catalog\Api\ProductCustomOptionRepositoryInterface Like this: $product->setHasOptions(1); $product->setCanSaveCustomOptions(true); foreach ($options as $arrayOption) { $isHasOptions = $product->getTypeInstance()->hasOptions($product); $option = \Magento\Framework\App\ObjectManager::...


1

Above answer is not working for me I have updated my observer code public function execute(\Magento\Framework\Event\Observer $observer) { $params = []; // If you want to redirect with data // $url = $this->_urlInterface->getUrl('checkout/cart/index',$params); $url = $this->_urlInterface->getUrl('checkout/...


1

Saving happens in a MySQL transaction and the delete_after event is triggered before the transaction is committed, so that you can do additional updates in the database within the same transaction. The delete_commit_after event is triggered after the transaction has been committed, i.e. when the changes were written to the database.


1

It is because you have printed information in the observer. I think it is not because you have used getRequest() in the observer. Try to see the result in this way. $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info(print_r($this->request->getParams(), ...


1

Did you try with : //\Magento\Framework\App\RequestInterface $this->_request->getParam('field_name'); Its working for me. Hope it will work for you too.


1

Try using \Magento\Framework\App\RequestInterface::getParams() In replacement for: \Magento\Framework\App\Request\Http::getParams()


1

You can use sales_model_service_quote_submit_success event you can save a value in the order table also. public function __construct( \Magento\Checkout\Model\Session $checkoutsession, \Magento\Sales\Model\Order $orderFacory ){ $this->orderFacory = $orderFacory; $this->_checkoutsession = $checkoutsession; } public function execute(\Magento\Framework\...


1

This will return current cart details. public function __construct( ... \Magento\Checkout\Model\Cart $cart, ... ) { $this->cart = $cart; } public function getCartDetails() { $cart= $this->cart->getQuote()->getAllVisibleItems(); } you can make an observer for the same on event checkout_cart_save_before your event.xml will ...


1

Use event sales_order_place_before to get quote id before save order And your observer code would be like this: public function execute(\Magento\Framework\Event\Observer $observer) { $QuoteID=$observer->getEvent()->getOrder()->getQuoteId(); }


1

Below is the event list used to get the order collections data. - sales_order_save_after - sales_order_invoice_save_after - sales_order_shipment_save_after - sales_order_creditmemo_save_after


Only top voted, non community-wiki answers of a minimum length are eligible