Skip to content

Commit

Permalink
[PW-7981] Change productUrl builder for line items (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
candemiralp committed Mar 3, 2023
1 parent e189d1a commit 48cd454
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/Handlers/AbstractPaymentMethodHandler.php
Expand Up @@ -606,10 +606,13 @@ protected function preparePaymentsRequest(
$this->getProduct($orderLine->getProductId(), $salesChannelContext->getContext()) :
null;

if (isset($product) && !is_null($product->getSeoUrls())) {
$hostname = $salesChannelContext->getSalesChannel()->getDomains()->first()->getUrl();
$productPath = $product->getSeoUrls()->first()->getPathInfo();
$productUrl = str_replace('//', '/', $hostname . $productPath);
// Add url for only real product and not for the custom cart items.
if (!is_null($product->getId())) {
$productUrl = sprintf(
"%s/detail/%s",
$salesChannelContext->getSalesChannel()->getDomains()->first()->getUrl(),
$product->getId()
);
} else {
$productUrl = null;
}
Expand Down Expand Up @@ -741,7 +744,6 @@ private function getProduct(string $productId, Context $context): ProductEntity
{
$criteria = new Criteria([$productId]);

$criteria->addAssociation('seoUrls');
$criteria->addAssociation('cover');
$criteria->addAssociation('categories');

Expand Down
13 changes: 7 additions & 6 deletions src/Service/PaymentRequestService.php
Expand Up @@ -375,11 +375,13 @@ public function getLineItems(
$item['imageUrl'] = $product->getCover()->getMedia()->getUrl();
}

if (!is_null($product->getSeoUrls())) {
$hostname = $salesChannelContext->getSalesChannel()->getDomains()->first()->getUrl();
$productPath = $product->getSeoUrls()->first()->getPathInfo();

$item['productUrl'] = str_replace('//', '/', $hostname . $productPath);
// Add url for only real product and not for the custom cart items.
if (!is_null($product->getId())) {
$item['productUrl'] = sprintf(
"%s/detail/%s",
$salesChannelContext->getSalesChannel()->getDomains()->first()->getUrl(),
$product->getId()
);
}

//Building open invoice line
Expand Down Expand Up @@ -448,7 +450,6 @@ public function getProduct(string $productId, Context $context): ProductEntity
{
$criteria = new Criteria([$productId]);

$criteria->addAssociation('seoUrls');
$criteria->addAssociation('cover');

/** @var ProductCollection $productCollection */
Expand Down

0 comments on commit 48cd454

Please sign in to comment.