I have a very strange issue with my store. I have an attribute (yes/no value) and when I echo the value on the listings page on the frontend of my Magento 2 store all products show the value as ‘no’.
Some of them are certainly set to yes and I have confirmed this in the admin panel.
List.phtml
<?php $ i=0; foreach ($ _productCollection as $ _product): $ i++ ?> <?php $ clearClass = $ themeHelper->getClearClass($ perrow, $ i) ?> <li class="item product product-item <?php if($ viewMode == 'grid'): ?> grid-template-<?php echo $ grid_tp ?> <?php echo $ colClass ?> <?php echo $ clearClass ?><?php endif ?>"> <?php $ swatches = $ block->getProductDetailsHtml($ _product); ?> <?php $ wlDataPost = $ block->getAddToWishlistParams($ _product); ?> <?php $ fk = $ block->getBlockHtml('formkey') ?> <?php $ postParams = $ block->getAddToCartPostParams($ _product); ?> <?php $ review = $ block->getReviewsSummaryHtml($ _product, $ templateType); ?> <?php $ prdPrice = $ block->getProductPrice($ _product) ?> <?php echo $ this->getLayout() ->createBlock('Magento\Framework\View\Element\Template') ->setProduct($ _product) ->setThemeHelper($ themeHelper) ->setImageHelper($ _imagehelper) ->setCatalogHelperOutput($ _helper) ->setQuickViewHelper($ quickViewHelper) ->setRatio($ ratio) ->setSize($ size) ->setCustomAttribute($ ct_attr) ->setPadding($ padding) ->setLazyLoadBaseImage($ baseImage) ->setCompare($ showCompare) ->setFk($ fk) ->setPostParams($ postParams) ->setReview($ review) ->setPrdPrice($ prdPrice) ->setWishList($ showWishList) ->setLazyLoad($ lazyLoad) ->setHoverChange($ change_img) ->setWishListPost($ wlDataPost) ->setTemplate($ templateFile) ->setSwatches($ swatches) ->setPos($ pos) ->toHtml(); ?> //This is the specific piece of code to get the attribute <?php echo $ _product->getAttributeText('can_buy') ; ?> </li> <?php endforeach; ?>
Can anyone please suggest what may be happening here/a fix?
Thank you,
Steve