Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MyVendorMyModuleObserver;
- class TotalCalcScore implements MagentoFrameworkEventObserverInterface
- {
- protected $_product;
- public function __construct(
- MagentoCatalogModelProductFactory $product
- ) {
- $this->_product = $product;
- }
- public function execute(
- MagentoFrameworkEventObserver $observer
- )
- {
- $productIds = $observer->getProductIds();
- foreach($productIds as $id){
- $product = $this->_product->create()->load($id);
- if($product->getId()){
- // attribute_first_count
- $value_offirst_count = $product->getattribute_first_count();
- // attribute_second_count
- $value_offsecond_score = $product->getattribute_second_count();
- // attribute_calculated_count
- $value_calculated_score = $product->getattribute_calculated_count();
- // calculate
- $value_calculated_score = $value_offsecond_score + $value_offirst_count
- //save calculated value
- //$product->setCalculatedValue($value_calculated_score);
- //save to attribute_calculated_score
- $product->setAttrCalculatedScore($value_calculated_score);
- $product->save();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement