Skip to content

Commit

Permalink
[shopsys] Persoo feed fixes (#2963)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLudvik authored Jan 4, 2024
2 parents 96835bc + 70b5d83 commit 02c2979
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Model/FeedItem/PersooFeedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig;
use Shopsys\FrameworkBundle\Component\String\TransformString;
use Shopsys\FrameworkBundle\Component\Translation\Translator;
use Shopsys\FrameworkBundle\Model\Category\CategoryRepository;
use Shopsys\FrameworkBundle\Model\Pricing\Currency\Currency;
use Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFacade;
use Shopsys\FrameworkBundle\Model\Pricing\Price;
use Shopsys\FrameworkBundle\Model\Product\Availability\ProductAvailabilityFacade;
use Shopsys\FrameworkBundle\Model\Product\Collection\ProductUrlsBatchLoader;
use Shopsys\FrameworkBundle\Model\Product\Flag\Flag;
use Shopsys\FrameworkBundle\Model\Product\Pricing\ProductPriceCalculationForCustomerUser;
Expand All @@ -25,13 +25,15 @@ class PersooFeedItemFactory
* @param \Shopsys\FrameworkBundle\Model\Product\Collection\ProductUrlsBatchLoader $productUrlsBatchLoader
* @param \Shopsys\FrameworkBundle\Model\Category\CategoryRepository $categoryRepository
* @param \Shopsys\FrameworkBundle\Model\Product\ProductCachedAttributesFacade $productCachedAttributesFacade
* @param \Shopsys\FrameworkBundle\Model\Product\Availability\ProductAvailabilityFacade $productAvailabilityFacade
*/
public function __construct(
protected readonly ProductPriceCalculationForCustomerUser $productPriceCalculationForCustomerUser,
protected readonly CurrencyFacade $currencyFacade,
protected readonly ProductUrlsBatchLoader $productUrlsBatchLoader,
protected readonly CategoryRepository $categoryRepository,
protected readonly ProductCachedAttributesFacade $productCachedAttributesFacade,
protected readonly ProductAvailabilityFacade $productAvailabilityFacade,
) {
}

Expand All @@ -45,9 +47,7 @@ public function create(Product $product, DomainConfig $domainConfig): PersooFeed
$locale = $domainConfig->getLocale();
$rootCategory = $this->categoryRepository->getRootCategory();
$mainCategory = $this->categoryRepository->getProductMainCategoryOnDomain($product, $domainConfig->getId());
$availability = $product->getCalculatedSellingDenied() === true ?
t('Out of stock', [], Translator::DEFAULT_TRANSLATION_DOMAIN, $locale) :
t('In stock', [], Translator::DEFAULT_TRANSLATION_DOMAIN, $locale);
$availability = $this->productAvailabilityFacade->getProductAvailabilityInformationByDomainId($product, $domainConfig->getId());
$productDescription = $product->isVariant() ? $product->getMainVariant()->getDescriptionAsPlainText($domainConfig->getId()) : $product->getDescriptionAsPlainText($domainConfig->getId());
$categories = $product->getCategoriesIndexedByDomainId()[$domainConfig->getId()];
$categoryHierarchyNamesByCategoryId = [];
Expand All @@ -60,7 +60,7 @@ public function create(Product $product, DomainConfig $domainConfig): PersooFeed
$categoryHierarchyNames[] = $category->getName($locale);
$categoryHierarchyIds[] = $category->getId();

while ($parent !== null && $parent !== $rootCategory) {
while ($parent !== null && $parent->getId() !== $rootCategory->getId()) {
$categoryHierarchyIds[] = $parent->getId();
$categoryHierarchyNames[] = $parent->getName($locale);
$parent = $parent->getParent();
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/feed.xml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<image_link>{{ item.imageLink }}</image_link>
{% endif -%}
<availability>{{ item.availability }}</availability>
<price>{{ item.price.priceWithVat|moneyFormat(2) }} {{ item.currency.code }}</price>
<price>{{ item.price.priceWithVat|moneyFormat(2) }}</price>
{% if item.brand is not null -%}
<brand>{{ item.brand }}</brand>
{% endif -%}
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/PersooFeedItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Shopsys\FrameworkBundle\Model\Pricing\Currency\Currency;
use Shopsys\FrameworkBundle\Model\Pricing\Currency\CurrencyFacade;
use Shopsys\FrameworkBundle\Model\Pricing\Price;
use Shopsys\FrameworkBundle\Model\Product\Availability\ProductAvailabilityFacade;
use Shopsys\FrameworkBundle\Model\Product\Brand\Brand;
use Shopsys\FrameworkBundle\Model\Product\Collection\ProductUrlsBatchLoader;
use Shopsys\FrameworkBundle\Model\Product\Flag\Flag;
Expand Down Expand Up @@ -120,12 +121,15 @@ protected function setUp(): void
$productCachedAttributesFacade = $this->createMock(ProductCachedAttributesFacade::class);
$productCachedAttributesFacade->method('getProductParameterValues')->willReturn([$productParameterValue]);

$productAvailabilityFacade = $this->createMock(ProductAvailabilityFacade::class);

$this->persooFeedItemFactory = new PersooFeedItemFactory(
$this->productPriceCalculationForCustomerUserMock,
$this->currencyFacadeMock,
$this->productUrlsBatchLoaderMock,
$categoryRepositoryMock,
$productCachedAttributesFacade,
$productAvailabilityFacade,
);
}

Expand Down

0 comments on commit 02c2979

Please sign in to comment.