Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WZ-4506:Fixed Category URL issue when there is multiple stores. #146

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 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 @@ -36,6 +37,10 @@ class ConfigurableProductsData

private $eventManager;

private $storeId;
private $allStoreBaseUrls = null;
private $currentStoreBaseUrl = [];

public function __construct(
ManagerInterface $eventManager,
BrandConfigurable $brandConfigurable,
Expand All @@ -46,7 +51,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,8 +68,14 @@ public function __construct(
$this->productsAttributesManager = $productsAttributesManager;
$this->hasToIgnoreCategories = $this->storeAutocompleteConfig->hasToIgnoreCategories();
$this->categoriesToIgnoreInAutoComplete = $this->storeAutocompleteConfig->getIgnoredCategories();
$this->storeManager = $storeManager;
}

public function setStore($storeId)
{
$this->storeId = $storeId;
}

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

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

if ($this->allStoreBaseUrls === null) {
$this->allStoreBaseUrls = $this->storeManager->getAllStoreBaseUrls();
alok0590 marked this conversation as resolved.
Show resolved Hide resolved
}

if (!isset($this->currentStoreBaseUrl[$this->storeId])) {
$this->currentStoreBaseUrl[$this->storeId] = $this->storeManager->getCurrentStoreBaseUrl();
alok0590 marked this conversation as resolved.
Show resolved Hide resolved
;
}

$currentStoreBaseUrl = null;

if ($this->currentStoreBaseUrl[$this->storeId] &&
alok0590 marked this conversation as resolved.
Show resolved Hide resolved
isset($this->currentStoreBaseUrl[$this->storeId]['base_url'])
) {
$currentStoreBaseUrl = $this->currentStoreBaseUrl[$this->storeId];
$currentStoreBaseUrl = $currentStoreBaseUrl['base_url'];
}

$categoryUrl = $category->getUrl();
foreach ($this->allStoreBaseUrls as $store) {
if (strpos($categoryUrl, $store['base_url']) === 0 &&
isset($currentStoreBaseUrl) && $currentStoreBaseUrl !== null) {
$categoryUrl = str_replace($store['base_url'], '', $categoryUrl);
$categoryUrl = $currentStoreBaseUrl."".$categoryUrl;
break;
}
}

$data =
['id' => $category->getId(),
'value' => $category->getName(),
Expand All @@ -276,7 +315,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 +332,7 @@ private function getCategoryArray($category)

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

return $data;
}
}
1 change: 1 addition & 0 deletions Services/Catalogue/Mappers/ProductsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function mapAll($products, $productReviews, $orderItems, $storeId)
$this->storeCatalogueConfig->setStore($storeId);
$this->productURLManager->setStore($storeId);
$this->productURLManager->fetchUrls($products);
$this->configurableProductsData->setStore($storeId);
$this->setAdminUrl();
$this->isBrandMandatory = $this->storeCatalogueConfig->isBrandMandatoryForSync();
$this->resetEntitiesToIgnore();
Expand Down
27 changes: 27 additions & 0 deletions Services/Store/StoreManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,31 @@ 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 $currentStore = [
'store_id' => $this->storeManager->getStore()->getId(),
'base_url' => $this->storeManager->getStore()->getBaseUrl(),
];
}
}
Loading