コード例 #1
0
 public function testAdd()
 {
     $attributeCode = 42;
     $optionMock = $this->getMock('\\Magento\\Eav\\Api\\Data\\AttributeOptionInterface');
     $this->eavOptionManagementMock->expects($this->once())->method('add')->with(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, $attributeCode, $optionMock)->willReturn(true);
     $this->assertTrue($this->model->add($attributeCode, $optionMock));
 }
コード例 #2
0
 protected function updateAll($updateData)
 {
     $result = 0;
     foreach ($updateData as $attributeUpdate) {
         if ($attributeUpdate['attribute_type'] == 'product') {
             if ($attributeUpdate['status'] == self::ADD_ATTRIBUTE_OPTION) {
                 $optionToAdd = $this->optionDataFactory->create();
                 $optionToAdd->setLabel($attributeUpdate['value'])->setSortOrder(0)->setIsDefault(0);
                 try {
                     $this->attributeOptionManagement->add($attributeUpdate['attribute_code'], $optionToAdd);
                     $result++;
                 } catch (\Exception $e) {
                     $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Unable to add attribute option', 'Error: ' . $e->getMessage());
                     $result = false;
                 }
             } else {
                 if ($attributeUpdate['status'] == self::AUTO_REMOVE_ATTRIBUTE_OPTION) {
                     try {
                         $this->attributeOptionManagement->delete($attributeUpdate['attribute_code'], $attributeUpdate['option_id']);
                         $result++;
                     } catch (\Exception $e) {
                         $this->shipperLogger->postInfo('Shipperhq_Shipper', 'Unable to remove attribute option', 'Error: ' . $e->getMessage());
                         $result = false;
                     }
                 }
             }
         } elseif ($attributeUpdate['attribute_type'] == 'global_setting') {
             $this->carrierConfigHandler->saveConfig('carriers/shipper/' . $attributeUpdate['attribute_code'], $attributeUpdate['value']);
         }
     }
     if ($result >= 0) {
         $this->checkSynchStatus(true);
     }
     return $result;
 }