Skip to content

Commit

Permalink
Added logic to set u_brand from appropriate Product's Attribute. Set …
Browse files Browse the repository at this point in the history
…v1.2.0
  • Loading branch information
Returnless committed Dec 20, 2021
1 parent 119e4ab commit 7f0e821
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
23 changes: 21 additions & 2 deletions Model/Api/OrderInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function getOrderInfoReturnless($incrementId)
$orderInfo['order_products'][$orderItemKey]['bundle_children'][$key]['images'][1]['http_path'] = $this->getImageByProduct1($product);
$orderInfo['order_products'][$orderItemKey]['bundle_children'][$key]['url'] = $product->getProductUrl();
$orderInfo['order_products'][$orderItemKey]['bundle_children'][$key]['categories_ids'] = $product->getCategoryIds();
$orderInfo['order_products'][$orderItemKey]['bundle_children'][$key]['u_brand'] = $product->getBrand();
$orderInfo['order_products'][$orderItemKey]['bundle_children'][$key]['u_brand'] = $this->getUBrand($product);

$eavAttributeCode = $this->config->getEanAttributeCode();

Expand All @@ -253,7 +253,7 @@ public function getOrderInfoReturnless($incrementId)
$orderInfo['order_products'][$orderItemKey]['images'][1]['http_path'] = $this->getImageByProduct1($product);
$orderInfo['order_products'][$orderItemKey]['url'] = $product->getProductUrl();
$orderInfo['order_products'][$orderItemKey]['categories_ids'] = $product->getCategoryIds();
$orderInfo['order_products'][$orderItemKey]['u_brand'] = $product->getBrand();
$orderInfo['order_products'][$orderItemKey]['u_brand'] = $this->getUBrand($product);

$eavAttributeCode = $this->config->getEanAttributeCode();

Expand Down Expand Up @@ -350,6 +350,25 @@ public function getImageByProduct($product)
return $image;
}

/**
* Method returns variable for Product's Brand Attribute
*
* @param $product
* @return null
*/
protected function getUBrand($product)
{
$brandAttributeCode = $this->config->getBrandAttributeCode();
$brandAttributeCode = !empty($brandAttributeCode) ? $brandAttributeCode : null;

$uBrand = null;
if (!empty($brandAttributeCode)) {
$uBrand = $product->getResource()->getAttribute($brandAttributeCode)->getFrontend()->getValue($product);
}

return $uBrand ? $uBrand : null;
}

/**
* @param $result
*/
Expand Down
20 changes: 20 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Config
*/
const CONFIG_EAN_ATTRIBUTE_CODE = 'returnless_connector/general/u_upc';

/**
* const CONFIG_BRAND_ATTRIBUTE_CODE
*/
const CONFIG_BRAND_ATTRIBUTE_CODE = 'returnless_connector/general/u_brand';

/**
* const CONFIG_SEPARATE_BUNDLE_PRODUCTS
*/
Expand Down Expand Up @@ -147,4 +152,19 @@ public function getSeparateBundle($store = null)

return $separateBundle;
}

/**
* @param null $store
* @return string
*/
public function getBrandAttributeCode($store = null)
{
$brandttributeCode = (string)$this->scopeConfig->getValue(
self::CONFIG_BRAND_ATTRIBUTE_CODE,
ScopeInterface::SCOPE_STORE,
$store
);

return $brandttributeCode;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"OSL-3.0",
"AFL-3.0"
],
"version": "1.1.9"
"version": "1.2.0"
}
4 changes: 4 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<label>EAN attribute code</label>
<comment><![CDATA[The name of the EAN attribute in your system]]></comment>
</field>
<field id="u_brand" translate="label" type="text" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Brand attribute code</label>
<comment><![CDATA[The name of the Brand attribute in your system]]></comment>
</field>
<field id="bundle_enabled" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Separate bundle products</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Returnless_Connector" setup_version="1.1.9">
<module name="Returnless_Connector" setup_version="1.2.0">
<sequence>
<module name="Magento_Sales"/>
</sequence>
Expand Down

0 comments on commit 7f0e821

Please sign in to comment.