Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #459 from Nosto/hotfix/3.7.7
Browse files Browse the repository at this point in the history
Hotfix 3.7.7 - Fix Attribute Names Translation
  • Loading branch information
supercid authored Nov 30, 2018
2 parents 6b224e2 + 163dc68 commit 099a025
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

### 3.7.7
* Fix an issue that would cause product attributes and custom fields to have a wrong translation

### 3.7.6
* Fix an issue in Magento Enterprise that would prevent to save a simple product if the logged user does not have permission to see the parent product.

Expand Down
21 changes: 14 additions & 7 deletions app/code/community/Nosto/Tagging/Model/Meta/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function loadData(Mage_Catalog_Model_Product $product, Mage_Core_Model_St
}
$brandAttribute = $dataHelper->getBrandAttribute($store);
if ($product->hasData($brandAttribute)) {
$this->setBrand($this->getAttributeValue($product, $brandAttribute));
$this->setBrand($this->getAttributeValue($product, $brandAttribute, $store->getId()));
}
if (($tags = $this->buildTags($product, $store)) !== array()) {
$this->setTag1($tags);
Expand All @@ -130,14 +130,13 @@ public function loadData(Mage_Catalog_Model_Product $product, Mage_Core_Model_St
if ($dataHelper->getUseSkus($store)) {
$this->amendSkus($product, $store);
}

if ($dataHelper->isMultiCurrencyMethodExchangeRate($store)) {
$this->setVariationId($store->getBaseCurrencyCode());
} elseif ($dataHelper->isVariationEnabled($store)) {
$this->amendVariations($product, $store);
}
if ($dataHelper->getUseCustomFields($store)) {
$this->setCustomFields($this->loadCustomFields($product));
$this->setCustomFields($this->loadCustomFields($product, $store));
}

Mage::dispatchEvent(
Expand Down Expand Up @@ -363,7 +362,7 @@ protected function amendAttributeTags(Mage_Catalog_Model_Product $product, Mage_
continue;
}
try {
$attributeValue = $this->getAttributeValue($product, $key);
$attributeValue = $this->getAttributeValue($product, $key, $store->getId());
if (empty($attributeValue)) {
continue;
}
Expand Down Expand Up @@ -501,22 +500,30 @@ public function __get($attribute)
*
* @param Mage_Catalog_Model_Product $product
* @param string $attributeName
* @param null|int $storeId The id of the current store
* @return string|null
* @suppress PhanUndeclaredMethod
*/
protected function getAttributeValue(Mage_Catalog_Model_Product $product, $attributeName)
protected function getAttributeValue(
Mage_Catalog_Model_Product $product,
$attributeName,
$storeId = null
)
{
$attribute = $product->getResource()->getAttribute($attributeName);
if ($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute) {
/** @noinspection PhpParamsInspection */
if ($storeId && method_exists($product, 'setStoreId')) {
$product->setStoreId($storeId);
}
$attributeValue = $product->getAttributeText($attributeName);
if (empty($attributeValue)) {
$attributeValue = $product->getData($attributeName);
}

if (is_scalar($attributeValue)) {
return trim($attributeValue);
} elseif (is_array($attributeValue)) {
}
if (is_array($attributeValue)) {
return implode(',', $attributeValue);
}
}
Expand Down
17 changes: 13 additions & 4 deletions app/code/community/Nosto/Tagging/Model/Meta/Product/Trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function amendCustomizableAttributes(Mage_Catalog_Model_Product $produ
foreach ($attributes as $mageAttr => $nostoAttr) {
$mapped = $nostoHelper->getMappedAttribute($mageAttr, $store);
if ($mapped) {
$value = $this->getAttributeValue($product, $mapped);
$value = $this->getAttributeValue($product, $mapped, $store->getId());
if (!empty($value)) {
$method = sprintf('set%s', ucfirst($nostoAttr));
$this->$method($value);
Expand All @@ -175,13 +175,21 @@ protected function amendCustomizableAttributes(Mage_Catalog_Model_Product $produ
*
* @param Mage_Catalog_Model_Product $product
* @param string $attributeName
* @param null|int $storeId
* @return string
* @suppress PhanUndeclaredMethod
*/
protected function getAttributeValue(Mage_Catalog_Model_Product $product, $attributeName)
protected function getAttributeValue(
Mage_Catalog_Model_Product $product,
$attributeName,
$storeId = null
)
{
$attribute = $product->getResource()->getAttribute($attributeName);
if ($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute) {
if ($storeId && method_exists($product, 'setStoreId')) {
$product->setStoreId($storeId);
}
$attributeData = $product->getData($attributeName);
/** @noinspection PhpParamsInspection */
$attributeValue = $product->getAttributeText($attributeName);
Expand All @@ -199,9 +207,10 @@ protected function getAttributeValue(Mage_Catalog_Model_Product $product, $attri
* Get the custom attributes
*
* @param Mage_Catalog_Model_Product $product
* @param Mage_Core_Model_Store $store
* @return array|null custom fields
*/
protected function loadCustomFields(Mage_Catalog_Model_Product $product)
protected function loadCustomFields(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store)
{
$customFields = array();

Expand All @@ -217,7 +226,7 @@ protected function loadCustomFields(Mage_Catalog_Model_Product $product)
)
) {
$attributeCode = $attribute->getAttributeCode();
$attributeValue = $this->getAttributeValue($product, $attributeCode);
$attributeValue = $this->getAttributeValue($product, $attributeCode, $store->getId());
if (is_scalar($attributeValue)) {
$customFields[$attributeCode] = $attributeValue;
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/community/Nosto/Tagging/Model/Meta/Sku.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function loadCustomFieldsFromAttributeSet(
/** @var Nosto_Tagging_Helper_Data $dataHelper */
$dataHelper = Mage::helper('nosto_tagging');
if ($dataHelper->getUseCustomFields($store)) {
$customFields = $this->loadCustomFields($product);
$customFields = $this->loadCustomFields($product, $store);
foreach ($customFields as $key => $value) {
$this->addCustomField($key, $value);
}
Expand All @@ -123,7 +123,7 @@ protected function loadCustomFieldsFromConfigurableAttributes(
try {
$attributeCode = $configurableAttribute['attribute_code'];
if (!array_key_exists($attributeCode, $this->getCustomFields())) {
$attributeValue = $this->getAttributeValue($sku, $attributeCode);
$attributeValue = $this->getAttributeValue($sku, $attributeCode, $store->getId());
if (is_scalar($attributeValue)) {
$this->addCustomField($attributeCode, $attributeValue);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Nosto/Tagging/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<config>
<modules>
<Nosto_Tagging>
<version>3.7.6</version>
<version>3.7.7</version>
</Nosto_Tagging>
</modules>
<global>
Expand Down

0 comments on commit 099a025

Please sign in to comment.