Example #1
0
 /**
  * Return Product attribute values array
  *
  * @param CatalogModelProduct $product
  * @return array Product attribute values
  */
 protected function _getAttributesMapByProduct(CatalogModelProduct $product)
 {
     $result = [];
     $group = $this->_config->getAttributeGroupsFlat();
     foreach ($this->_getAttributesCollection() as $attribute) {
         $productAttribute = $this->_gsProduct->getProductAttribute($product, $attribute->getAttributeId());
         if ($productAttribute !== null) {
             // define final attribute name
             if ($attribute->getGcontentAttribute()) {
                 $name = $attribute->getGcontentAttribute();
             } else {
                 $name = $this->_gsProduct->getAttributeLabel($productAttribute, $product->getStoreId());
             }
             if ($name !== null) {
                 $name = $this->_googleShoppingHelper->normalizeName($name);
                 if (isset($group[$name])) {
                     // if attribute is in the group
                     if (!isset($result[$group[$name]])) {
                         $result[$group[$name]] = $this->_attributeFactory->createAttribute($group[$name]);
                     }
                     // add group attribute to parent attribute
                     $result[$group[$name]]->addData(['group_attribute_' . $name => $this->_attributeFactory->createAttribute($name)->addData($attribute->getData())]);
                     unset($group[$name]);
                 } else {
                     if (!isset($result[$name])) {
                         $result[$name] = $this->_attributeFactory->createAttribute($name);
                     }
                     $result[$name]->addData($attribute->getData());
                 }
             }
         }
     }
     return $this->_initGroupAttributes($result);
 }