Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <event name="checkout_cart_add_product_complete">
  2. <observer name="customprice" instance="NsModuleObserverCustomPrice" />
  3. </event>
  4. <event name="checkout_cart_update_item_complete">
  5. <observer name="custompriceupdate" instance="NsModuleObserverCustomPrice" />
  6. </event>
  7. <event name="sales_quote_item_qty_set_after">
  8. <observer name="custompriceupdateqty" instance="NsModuleObserverCustomPrice" />
  9. </event>
  10.  
  11. public function execute(MagentoFrameworkEventObserver $observer)
  12. {
  13. $cart = $this->cart;
  14. $quote = $cart->getQuote();
  15. $items = $cart->getQuote()->getAllItems();
  16. $basetotal = 0;
  17. foreach ($items as $itemforprice) {
  18. $total = $this->processItem($itemforprice);
  19. $basetotal += $total;
  20. }
  21.  
  22. $quote->setSubtotal($basetotal);
  23. $quote->setGrandTotal($basetotal);
  24. $quote->setBaseSubtotal($basetotal);
  25. $quote->setBaseGrandTotal($basetotal);
  26. $quote->setSubtotalWithDiscount($basetotal);
  27. $quote->setBaseSubtotalWithDiscount($basetotal);
  28. $quote->save();
  29. }
  30.  
  31. private function processItem($itemforprice)
  32. {
  33. $myprice = 100;
  34. $total = $myprice * $qty;
  35.  
  36. $itemforprice->setCustomPrice($myprice);
  37. $itemforprice->setOriginalCustomPrice($myprice);
  38. $itemforprice->setBasePrice($myprice);
  39. $itemforprice->setPrice($myprice);
  40.  
  41. $itemforprice->setRowTotal($total);
  42. $itemforprice->setBaseRowTotal($total);
  43. $itemforprice->setRowTotalInclTax($total);
  44. $itemforprice->setBaseRowTotalInclTax($total);
  45.  
  46. $itemforprice->save();
  47.  
  48. return $total;
  49. }
  50.  
  51. $this->_eventManager->dispatch('sales_quote_item_qty_set_after', ['item' => $this]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement