Skip to content

Commit

Permalink
WZ-4506:Fixed Category URL issue when there is multiple stores.
Browse files Browse the repository at this point in the history
  • Loading branch information
smit-kandiya committed Oct 21, 2024
1 parent 43b16f3 commit ce589e6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
29 changes: 24 additions & 5 deletions Services/Catalogue/Mappers/ConfigurableProductsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Wizzy\Search\Services\Queue\SessionStorage\CategoriesSessionStorage;
use Wizzy\Search\Services\Store\StoreAutocompleteConfig;
use Magento\Framework\Event\ManagerInterface;
use Wizzy\Search\Services\Store\StoreManager;

class ConfigurableProductsData
{
Expand All @@ -22,7 +23,7 @@ class ConfigurableProductsData
private $genderConfigurable;
private $colorConfigurable;
private $sizeConfigurable;

private $storeManager;
private $storeAutocompleteConfig;

private $categoriesManager;
Expand All @@ -46,7 +47,8 @@ public function __construct(
StoreAutocompleteConfig $storeAutocompleteConfig,
AttributesManager $attributesManager,
CategoriesSessionStorage $categoriesSessionStorage,
ProductsAttributesManager $productsAttributesManager
ProductsAttributesManager $productsAttributesManager,
StoreManager $storeManager
) {
$this->eventManager = $eventManager;
$this->brandConfigurable = $brandConfigurable;
Expand All @@ -62,6 +64,7 @@ public function __construct(
$this->productsAttributesManager = $productsAttributesManager;
$this->hasToIgnoreCategories = $this->storeAutocompleteConfig->hasToIgnoreCategories();
$this->categoriesToIgnoreInAutoComplete = $this->storeAutocompleteConfig->getIgnoredCategories();
$this->storeManager = $storeManager;
}

public function getBrand($categories, $attributes, $storeId)
Expand Down Expand Up @@ -233,7 +236,6 @@ public function getProductCategories($product)
);
return $dataObject->getDataByKey('categories');
}

private function getCategoryArray($category)
{
$pathIds = $category->getPathIds();
Expand Down Expand Up @@ -266,6 +268,23 @@ private function getCategoryArray($category)
$parentUrlKey = '';
}

$storeUrls = null;

if ($storeUrls === null) {
$storeUrls = $this->storeManager->getAllStoreBaseUrls();
}

$currentStoreBaseUrl = $this->storeManager->getCurrentStoreBaseUrl();
$categoryUrl = $category->getUrl();
foreach ($storeUrls as $store) {
if (strpos($categoryUrl, $store['base_url']) === 0) {
$categoryUrl = str_replace($store['base_url'], '', $categoryUrl);
break;
}
}

$categoryUrl = $currentStoreBaseUrl."".$categoryUrl;

$data =
['id' => $category->getId(),
'value' => $category->getName(),
Expand All @@ -276,7 +295,7 @@ private function getCategoryArray($category)
'level' => (int) $category->getLevel(),
'description' => ($category->getDescription()) ? $category->getDescription() : '',
'image' => ($category->getImageUrl()) ? $category->getImageUrl() : '',
'url' => $category->getUrl(),
'url' => $categoryUrl,
'isActive'=> $category->getIsActive(),
'pathIds' => $pathIds,
'parentId' => $parentId,
Expand All @@ -293,7 +312,7 @@ private function getCategoryArray($category)

$data['includeInMenu'] = $includeInMenu;
$data['isSearchable'] = $isSearchable;

return $data;
}
}
23 changes: 23 additions & 0 deletions Services/Store/StoreManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,27 @@ public function getAllStores()

return $storeIds;
}

public function getAllStoreBaseUrls()
{
$baseUrls = [];
$storeIds = $this->getActivateWizzyStores();

foreach ($storeIds as $storeId) {
$store = $this->storeManager->getStore($storeId);
$storeId = $store->getId();
$baseUrl = $store->getBaseUrl();

$baseUrls[] = [
'store_id' => $storeId,
'base_url' => $baseUrl,
];
}

return $baseUrls;
}
public function getCurrentStoreBaseUrl()
{
return $this->storeManager->getStore()->getBaseUrl();
}
}

0 comments on commit ce589e6

Please sign in to comment.