Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. namespace MyVendorMyModuleObserver;
  2.  
  3.  
  4. class TotalCalcScore implements MagentoFrameworkEventObserverInterface
  5. {
  6.  
  7. protected $_product;
  8.  
  9.  
  10. public function __construct(
  11. MagentoCatalogModelProductFactory $product
  12. ) {
  13. $this->_product = $product;
  14. }
  15.  
  16.  
  17. public function execute(
  18. MagentoFrameworkEventObserver $observer
  19. )
  20. {
  21. $productIds = $observer->getProductIds();
  22. foreach($productIds as $id){
  23. $product = $this->_product->create()->load($id);
  24.  
  25. if($product->getId()){
  26.  
  27.  
  28. // attribute_first_count
  29. $value_offirst_count = $product->getattribute_first_count();
  30. // attribute_second_count
  31. $value_offsecond_score = $product->getattribute_second_count();
  32. // attribute_calculated_count
  33. $value_calculated_score = $product->getattribute_calculated_count();
  34.  
  35.  
  36.  
  37. // calculate
  38. $value_calculated_score = $value_offsecond_score + $value_offirst_count
  39.  
  40. //save calculated value
  41. //$product->setCalculatedValue($value_calculated_score);
  42. //save to attribute_calculated_score
  43. $product->setAttrCalculatedScore($value_calculated_score);
  44.  
  45. $product->save();
  46. }
  47.  
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement