2

I want to check "Set Product as New" from list.phtml in magento2(EE)?

enter image description here

I have tring to below methods:

$_product->getData('is_new') //not working
$_product->getIsNew() //not working

Anybody have any solution for this issue.

4
  • try to get this way -> <?php $_helper = $this->helper('Magento\Catalog\Helper\Output');?> <?php echo $helper->productAttribute($_product, $_product->getIsNew(), 'isnew') ?>
    – P_U
    Commented Jul 30, 2018 at 10:48
  • @PareshaU not working Commented Jul 30, 2018 at 11:22
  • 1
    Have you figured out how is_new works for Enterprise? Could you please explain? Commented May 3, 2021 at 16:19
  • Have you ever figured it out?
    – Black
    Commented Jul 6, 2021 at 12:14

2 Answers 2

1

"Set Product as New" in admin just creates a row in table "catalog_product_entity_datetime" and attribute_code in eav_attribute table is "news_from_date" so from list it can be reached like

$_product->getNewsFromDate()

but it will return a value like "2021-08-10 15:21:26" as it is datetime. When disabled it simply deletes the row in catalog_product_entity_datetime

1
  • Thanks, this helped me much.
    – xpoback
    Commented Sep 14, 2022 at 17:16
-2

If you have the product available, you can use this logic to check if it is a new product:

/**
 * Check if the given product is new and return true if it is.
 *
 * Should the Magento logic change, look in vendor/magento/module-catalog/Block/Product/NewProduct.php
 *
 * @param ProductInterface $product
 * @return boolean
 */
public function showNewLabel(ProductInterface $product): bool
{
    $newsFromDate = $product->getNewsFromDate();
    $newsToDate = $product->getNewsToDate();
    if (!$newsFromDate && !$newsToDate) {
        return false;
    }

    return $this->timezone->isScopeDateInInterval(
        $product->getStore(),
        $newsFromDate,
        $newsToDate
    );
}
1
  • 1
    For enterprise edition, new from and new to date attributes are not showing. Commented May 3, 2021 at 16:19

Your Answer

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

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