如果未填写日期,则显示产品

时间:2014-04-07 12:58:18

标签: php magento

我已经活跃于'并且'活跃于'日期选择器。我可以在设置日期时显示产品信息。

$giftActiveFrom = $_prod->getData('product_gift_active_from');
$giftActiveTo = $_prod->getData('product_gift_active_to');
$timestamp1 = strtotime($giftActiveFrom);
$timeNow = time();
$timestamp2 = strtotime($giftActiveTo);
if(!($timeNow > $timestamp1 && $timeNow < $timestamp2)){
    return parent::productAttribute($product, $attributeHtml, $attributeName);
}

即使未设置日期,如何显示产品。也就是说,如果未选择当前激活和激活,我还需要显示产品信息。 帮助!

1 个答案:

答案 0 :(得分:0)

如果产品日期/时间未设置/为空,请尝试设置默认时间戳:

$timestamp2 = (!empty(strtotime($giftActiveTo))) ? strtotime($giftActiveTo) : strtotime(date("Y-m-d H:i:s"));