0

I have setup 2 Store Views i want to call different attributes based on store view on category and product detail pages.

Screenshot 1 https://nimb.ws/ljVb0W

if store id == 1

getResource()->getAttribute('fit-option1'); if ($attributeName) { $labelValue = $attributeName->getFrontend()->getValue($_product); } echo $labelValue; // END DISPLAY ATTRIBUTE ?>

else if store id == 2

getResource()->getAttribute('fit-option2'); if ($attributeName) { $labelValue = $attributeName->getFrontend()->getValue($_product); } echo $labelValue; // END DISPLAY ATTRIBUTE ?>
asked Aug 12, 2020 at 8:03

2 Answers 2

0

You can separate your login by store id as below.

namespace Vendor\Module\Block;
class Module extends \Magento\Framework\View\Element\Template
{
 protected $_storeManager; 
 public function __construct(
 \Magento\Backend\Block\Template\Context $context, 
 \Magento\Store\Model\StoreManagerInterface $storeManager, 
 array $data = []
 )
 { 
 $this->_storeManager = $storeManager; 
 parent::__construct($context, $data);
 }
 /**
 * Get store identifier
 *
 * @return int
 */
 public function getStoreId()
 {
 return $this->_storeManager->getStore()->getId();
 }
}

in your phtml file you can use above block and get store id as below.

if($block->getStoreId() == 1 } 
{
fit-option1
}
if($block->getStoreId() == 2 } 
{
fit-option2
}
answered Aug 12, 2020 at 9:45
0
0

Could you please guide where to add below code

namespace Vendor\Module\Block; class Module extends \Magento\Framework\View\Element\Template { protected $_storeManager;

public function __construct(
 \Magento\Backend\Block\Template\Context $context, 
 \Magento\Store\Model\StoreManagerInterface $storeManager, 
 array $data = []
)
{ 
 $this->_storeManager = $storeManager; 
 parent::__construct($context, $data);
}
/**
 * Get store identifier
 *
 * @return int
 */
public function getStoreId()
{
 return $this->_storeManager->getStore()->getId();
}

}

answered Aug 19, 2020 at 3:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.