コード例 #1
0
 public function testGetItems()
 {
     $attributeCode = 10;
     $this->eavOptionManagementMock->expects($this->once())->method('getItems')->with(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE, $attributeCode)->willReturn([]);
     $this->assertEquals([], $this->model->getItems($attributeCode));
 }
コード例 #2
0
 protected function compareAttributeData($latestAttributes)
 {
     $result = array();
     $productAttributes = $this->shipperDataHelper->getProductAttributes();
     foreach ($latestAttributes as $attribute) {
         switch ($attribute->type) {
             case 'product':
                 try {
                     $existingAttributeOptions = array();
                     if (!in_array($attribute->code, $productAttributes)) {
                         $this->shipperLogger->postDebug('Shipperhq_Shipper', 'Attribute ' . $attribute->code . ' does not exist.', '');
                         continue;
                     }
                     $existingAttributeInfo = $this->attributeOptionManagement->getItems($attribute->code);
                     if (is_array($existingAttributeInfo)) {
                         $existingAttributeOptions = $existingAttributeInfo;
                     }
                 } catch (\Exception $e) {
                     $e->getMessage();
                     $this->shipperLogger->postDebug('Shipperhq_Shipper', 'Unable to find attribute ' . $attribute->code, 'Error: ' . $e->getMessage());
                     $result = false;
                     break;
                 }
                 $trackValues = $existingAttributeOptions;
                 foreach ($attribute->attributes as $latestValue) {
                     $found = false;
                     foreach ($existingAttributeOptions as $key => $option) {
                         if ($option->getLabel() == $latestValue->name) {
                             $found = true;
                             unset($trackValues[$key]);
                             continue;
                         }
                     }
                     if (!$found) {
                         $result[] = array('attribute_type' => $attribute->type, 'attribute_code' => $attribute->code, 'value' => $latestValue->name, 'status' => self::ADD_ATTRIBUTE_OPTION, 'date_added' => date('Y-m-d H:i:s'));
                     }
                 }
                 if (count($trackValues) > 0) {
                     //TODO add store selector in here
                     $storeId = '';
                     foreach ($trackValues as $key => $option) {
                         if (ctype_space($option->getLabel()) || $option->getLabel() == '') {
                             unset($trackValues[$key]);
                             continue;
                         }
                         $isAssigned = $this->getIsAttributeValueUsed($attribute->code, $option->getValue(), $storeId, true);
                         $deleteFlag = self::AUTO_REMOVE_ATTRIBUTE_OPTION;
                         if ($isAssigned) {
                             $deleteFlag = self::REMOVE_ATTRIBUTE_OPTION;
                         }
                         $result[] = array('attribute_type' => $attribute->type, 'attribute_code' => $attribute->code, 'value' => $option->getLabel(), 'option_id' => $option->getValue(), 'status' => $deleteFlag, 'date_added' => date('Y-m-d H:i:s'));
                     }
                 }
                 break;
             case 'global':
                 if ($attribute->code == 'global_settings') {
                     foreach ($attribute->attributes as $globalSetting) {
                         $value = $globalSetting->value == 'true' ? 1 : 0;
                         if ($this->shipperDataHelper->getConfigValue('carriers/shipper/' . $globalSetting->code) != $value) {
                             $result[] = array('attribute_type' => 'global_setting', 'attribute_code' => $globalSetting->code, 'value' => $value, 'option_id' => '', 'status' => self::ADD_ATTRIBUTE_OPTION, 'date_added' => date('Y-m-d H:i:s'));
                         }
                     }
                 }
             case 'customer':
                 //compare customer groups
                 break;
             default:
                 break;
         }
     }
     $this->shipperLogger->postDebug('Shipperhq_Shipper', 'Compare attributes result: ', $result);
     return $result;
 }