MarketingAttribute example

public function __construct(Shopware_Components_Config $config)
    {
        $this->config = $config;
    }

    /** * {@inheritdoc} */
    public function getProductAttribute(ListProduct $product)
    {
        $attribute = new MarketingAttribute();

        $today = new DateTime();

        $attribute->setIsNew(false);

        if ($product->getCreatedAt() instanceof DateTimeInterface) {
            $diff = $today->diff($product->getCreatedAt());
            $marker = (int) $this->config->get('markAsNew');

            $attribute->setIsNew(
                $diff->days <= $marker || $product->getCreatedAt() > $today
            );
Home | Imprint | This part of the site doesn't use cookies.