30 lines
818 B
PHP
30 lines
818 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\KupShopBundle\DiscountFieldDefinition;
|
|
|
|
/**
|
|
* Wraps `DiscountFieldDefinitionInterface` and checks if real discount is set. When real discount is not set, no discount is displayed.
|
|
*
|
|
* @property AbstractDiscountFieldDefinition $fallback
|
|
*/
|
|
class ExplicitDiscountFieldDefinition extends AbstractDiscountFieldDefinition
|
|
{
|
|
public function __construct(DiscountFieldDefinitionInterface $fallback)
|
|
{
|
|
$this->setFallback($fallback);
|
|
}
|
|
|
|
public function getField(): string
|
|
{
|
|
// discount must be explicitly defined on the product to be displayed
|
|
return "IF({$this->fallback->getColumn()}>0, {$this->fallback->getField()}, 0)";
|
|
}
|
|
|
|
public function getSpec(): callable
|
|
{
|
|
return $this->fallback->getSpec();
|
|
}
|
|
}
|