Skip to content

Commit

Permalink
added time-limited price lists with product special prices (#3628)
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmannmartin authored Jan 17, 2025
2 parents 8c77662 + ab93cdc commit 7776e9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Model/FeedItem/LuigisBoxProductFeedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LuigisBoxProductFeedItem implements FeedItemInterface
* @param string $availabilityText
* @param int $availabilityRank
* @param \Shopsys\FrameworkBundle\Model\Pricing\Price $price
* @param \Shopsys\FrameworkBundle\Model\Pricing\Price $basicPrice
* @param \Shopsys\FrameworkBundle\Model\Pricing\Currency\Currency $currency
* @param int $mainCategoryId
* @param string $url
Expand All @@ -46,6 +47,7 @@ public function __construct(
protected readonly string $availabilityText,
protected readonly int $availabilityRank,
protected readonly Price $price,
protected readonly Price $basicPrice,
protected readonly Currency $currency,
protected readonly int $mainCategoryId,
protected readonly string $url,
Expand Down Expand Up @@ -179,6 +181,18 @@ public function getPrice(): Price
return $this->price;
}

/**
* @return \Shopsys\FrameworkBundle\Model\Pricing\Price|null
*/
public function getOldPrice(): ?Price
{
if ($this->price->equals($this->basicPrice)) {
return null;
}

return $this->basicPrice;
}

/**
* @return \Shopsys\FrameworkBundle\Model\Pricing\Currency\Currency
*/
Expand Down
15 changes: 14 additions & 1 deletion src/Model/FeedItem/LuigisBoxProductFeedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function create(Product $product, DomainConfig $domainConfig): LuigisBoxP
$availabilityText,
$this->getAvailabilityRank($product, $domainConfig),
$this->getPrice($product, $domainConfig),
$this->getBasicPrice($product, $domainConfig),
$this->getCurrency($domainConfig),
$mainCategory->getId(),
$this->productUrlsBatchLoader->getProductUrl($product, $domainConfig),
Expand Down Expand Up @@ -121,7 +122,19 @@ protected function getPrice(Product $product, DomainConfig $domainConfig): Price
return $this->productPriceCalculationForCustomerUser->calculatePriceForCustomerUserAndDomainId(
$product,
$domainConfig->getId(),
null,
);
}

/**
* @param \Shopsys\FrameworkBundle\Model\Product\Product $product
* @param \Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig $domainConfig
* @return \Shopsys\FrameworkBundle\Model\Pricing\Price
*/
protected function getBasicPrice(Product $product, DomainConfig $domainConfig): Price
{
return $this->productPriceCalculationForCustomerUser->calculateBasicPriceForCustomerUserAndDomainId(
$product,
$domainConfig->getId(),
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Resources/views/feed.xml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<brand>{{ item.brand }}</brand>
{% endif -%}
<price>{{ item.price.priceWithVat|moneyFormat(2) }} {{ item.currency.code }}</price>
{% if item.oldPrice %}
<old_price>{{ item.oldPrice.priceWithVat|moneyFormat(2) }} {{ item.currency.code }}</old_price>
{% endif %}
{% if item.imageLinkS is not null -%}
<image_link_s>{{ item.imageLinkS }}</image_link_s>
<image_link_m>{{ item.imageLinkM }}</image_link_m>
Expand Down

0 comments on commit 7776e9a

Please sign in to comment.