/**
  * Create attribute model
  *
  * @param string $name
  * @return \Magento\GoogleShopping\Model\Attribute\DefaultAttribute
  */
 public function createAttribute($name)
 {
     $modelName = 'Magento\\GoogleShopping\\Model\\Attribute\\' . $this->_string->upperCaseWords($this->_googleShoppingHelper->normalizeName($name));
     try {
         /** @var \Magento\GoogleShopping\Model\Attribute\DefaultAttribute $attributeModel */
         $attributeModel = $this->_objectManager->create($modelName);
         if (!$attributeModel) {
             $attributeModel = $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Attribute\\DefaultAttribute');
         }
     } catch (\Exception $e) {
         $attributeModel = $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Attribute\\DefaultAttribute');
     }
     $attributeModel->setName($name);
     return $attributeModel;
 }
Esempio n. 2
0
 /**
  * Remove attributes which were removed from mapping.
  *
  * @param Entry $entry
  * @param string[] $existAttributes
  * @return Entry
  */
 protected function _removeNonexistentAttributes($entry, $existAttributes)
 {
     // attributes which can't be removed
     $ignoredAttributes = ["id", "image_link", "content_language", "target_country", "expiration_date", "adult"];
     $contentAttributes = $entry->getContentAttributes();
     foreach ($contentAttributes as $contentAttribute) {
         $name = $this->_googleShoppingHelper->normalizeName($contentAttribute->getName());
         if (!in_array($name, $ignoredAttributes) && !in_array($existAttributes, $existAttributes)) {
             $entry->removeContentAttribute($name);
         }
     }
     return $entry;
 }
Esempio n. 3
0
 /**
  * @param string $name
  * @param string $normalizedName
  *
  * @dataProvider nameDataProvider
  */
 public function testNormalizeName($name, $normalizedName)
 {
     $resultingName = $this->data->normalizeName($name);
     $this->assertEquals($normalizedName, $resultingName);
 }