/**
  * After delete attribute check rules that contains deleted attribute
  * If rules was found they will seted to inactive and added notice to admin session
  *
  * @param EventObserver $observer
  * @return $this
  */
 public function execute(EventObserver $observer)
 {
     $attribute = $observer->getEvent()->getAttribute();
     if ($attribute->getIsUsedForPromoRules()) {
         $this->checkSalesRulesAvailability->checkSalesRulesAvailability($attribute->getAttributeCode());
     }
     return $this;
 }
 /**
  * After save attribute if it is not used for promo rules already check rules for containing this attribute
  *
  * @param EventObserver $observer
  * @return $this
  */
 public function execute(EventObserver $observer)
 {
     $attribute = $observer->getEvent()->getAttribute();
     if ($attribute->dataHasChangedFor('is_used_for_promo_rules') && !$attribute->getIsUsedForPromoRules()) {
         $this->checkSalesRulesAvailability->checkSalesRulesAvailability($attribute->getAttributeCode());
     }
     return $this;
 }
 public function testCatalogAttributeDeleteAfter()
 {
     $attributeCode = 'attributeCode';
     $observer = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false);
     $event = $this->getMock('Magento\\Framework\\Event', ['getAttribute', '__wakeup'], [], '', false);
     $attribute = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', ['dataHasChangedFor', 'getIsUsedForPromoRules', 'getAttributeCode', '__wakeup'], [], '', false);
     $observer->expects($this->once())->method('getEvent')->will($this->returnValue($event));
     $event->expects($this->any())->method('getAttribute')->will($this->returnValue($attribute));
     $attribute->expects($this->any())->method('getIsUsedForPromoRules')->will($this->returnValue(true));
     $attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->checkSalesRulesAvailability->expects($this->once())->method('checkSalesRulesAvailability')->willReturn('true');
     $this->assertEquals($this->model, $this->model->execute($observer));
 }