I create one custom date attribute for my products in backend:
I need to get the attribute value in the products list page and to check if the product have any data added for the product.
I try something like this but is not work well:
$expectedInDate = $_product->getResource()->getAttribute('expecdate')->getFrontend()->getValue($_product);
if(isset($expectedInDate)) :
...........
endif;
What is the correct way to get data attribute value and to check if has data setup per current product?
The entire code:
<?php $timezoneInterface = $objectManager->create('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); ?>
<?php $expectedInDate = $_product->getResource()->getAttribute('expecdate')->getFrontend()->getValue($_product); ?>
<?php if ($StockState->getStockQty($_product->getId(), $_product->getStore()->getWebsiteId()) > 0 ): ?>
<div class="stock available"><span><?= /* @escapeNotVerified */ __('In stock') ?></span></div>
<?php else: ?>
<?php if($expectedInDate) : ?>
<?php $date = $timezoneInterface->date($expectedInDate)->format('m/d/Y');?>
<div class="stock available-in"><span><?= /* @escapeNotVerified */ __('Available in:') ?><?php echo $date; ?></span></div>
<?php else: ?>
<div class="stock unavailable"><span><?= /* @escapeNotVerified */ __('Out of stock') ?></span></div>
<?php endif; ?>
<?php endif; ?>
$_product->getExpecdate();
? What about the flag "Used in Product Listing", is it set to yes?