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 ?>

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
}
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();
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.