Skip to content

Commit

Permalink
Merge pull request #17 from aligent/feature/BEG-160-fix-cache-url-to-…
Browse files Browse the repository at this point in the history
…store-url

BEG-160 | Created a fix to get the store URL for the recache request
  • Loading branch information
aligent-lturner authored Apr 12, 2024
2 parents d0eb55b + b4bcf59 commit daf3633
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
7 changes: 7 additions & 0 deletions Api/PrerenderClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@

interface PrerenderClientInterface
{
/**
* Call Prerender service API to recache list of URLs
*
* @param array $urls
* @param int $storeId
* @return void
*/
public function recacheUrls(array $urls, int $storeId): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
use Magento\Framework\Mview\ViewInterface;
use Magento\Framework\Mview\Config;
use Magento\Framework\Mview\View\Changelog;
use Magento\Framework\Mview\View\Subscription;

/**
* Subscription model class for "catalog_product_link" table
*/
class CatalogProductLinkSubscription extends \Magento\Framework\Mview\View\Subscription
class CatalogProductLinkSubscription extends Subscription
{
private const CATALOG_PRODUCT_LINK_PRODUCT_ID = 'product_id';

Expand Down
15 changes: 5 additions & 10 deletions Model/Url/GetUrlsForCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Url;
use Magento\Store\Model\App\Emulation;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
Expand All @@ -25,9 +24,6 @@ class GetUrlsForCategories
/** @var Emulation */
private Emulation $emulation;

/** @var Url */
private Url $url;

/**
*
* @param CollectionFactory $categoryCollectionFactory
Expand All @@ -37,13 +33,11 @@ class GetUrlsForCategories
public function __construct(
CollectionFactory $categoryCollectionFactory,
StoreManagerInterface $storeManager,
Emulation $emulation,
Url $url
Emulation $emulation
) {
$this->categoryCollectionFactory = $categoryCollectionFactory;
$this->storeManager = $storeManager;
$this->emulation = $emulation;
$this->url = $url;
}

/**
Expand Down Expand Up @@ -79,10 +73,11 @@ public function execute(array $categoryIds, int $storeId): array
continue;
}
try {
$url = $this->url->getUrl($urlPath, ['_scope_to_url' => true]);
// Retrieve URL using store configuration
$url = $store->getUrl('', ['_direct' => $urlPath]);

// remove trailing slashes and parameters from the url
$urls[] = substr($url, 0, strrpos($url, '/'));
// Remove trailing slashes from urls
$urls[] = rtrim($url, '/');
} catch (NoSuchEntityException $e) {
continue;
}
Expand Down
16 changes: 6 additions & 10 deletions Model/Url/GetUrlsForProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*/

declare(strict_types=1);

namespace Aligent\Prerender\Model\Url;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Url;
use Magento\Store\Model\App\Emulation;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
Expand All @@ -25,9 +25,6 @@ class GetUrlsForProducts
/** @var Emulation */
private Emulation $emulation;

/** @var Url */
private Url $url;

/**
*
* @param CollectionFactory $productCollectionFactory
Expand All @@ -37,13 +34,11 @@ class GetUrlsForProducts
public function __construct(
CollectionFactory $productCollectionFactory,
StoreManagerInterface $storeManager,
Emulation $emulation,
Url $url
Emulation $emulation
) {
$this->productCollectionFactory = $productCollectionFactory;
$this->storeManager = $storeManager;
$this->emulation = $emulation;
$this->url = $url;
}

/**
Expand Down Expand Up @@ -81,10 +76,11 @@ public function execute(array $productIds, int $storeId): array
continue;
}
try {
$url = $this->url->getUrl($urlPath, ['_scope_to_url' => true]);
// Retrieve URL using store configuration
$url = $store->getUrl('', ['_direct' => $urlPath]);

// remove trailing slashes and parameters from the url
$urls[] = substr($url, 0, strrpos($url, '/'));
// Remove trailing slashes from urls
$urls[] = rtrim($url, '/');
} catch (NoSuchEntityException $e) {
continue;
}
Expand Down

0 comments on commit daf3633

Please sign in to comment.