-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
187 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Doofinder\Feed\Api; | ||
|
||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
use Magento\Catalog\Api\Data\CategoryProductSearchResultInterface; | ||
|
||
interface CategoryListInterface | ||
{ | ||
/** | ||
* Get category list | ||
* | ||
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria | ||
* @return \Magento\Catalog\Api\Data\CategorySearchResultsInterface | ||
* @since 102.0.0 | ||
*/ | ||
public function getList(SearchCriteriaInterface $searchCriteria): CategoryProductSearchResultInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Doofinder\Feed\Model; | ||
|
||
use Magento\Catalog\Model\CategoryList; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Catalog\Api\Data\CategoryInterface; | ||
use Magento\Catalog\Api\CategoryRepositoryInterface; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
use Magento\Framework\Api\FilterBuilder; | ||
|
||
class CategoryListRepository implements \Magento\Catalog\Api\CategoryListInterface | ||
{ | ||
protected $categoryRepository; | ||
protected $searchCriteriaBuilder; | ||
protected $filterBuilder; | ||
protected $scopeConfig; | ||
protected $storeManager; | ||
protected $categoryInterface; | ||
protected $categoryRepositoryInterface; | ||
|
||
public function __construct( | ||
CategoryList $categoryRepository, | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
FilterBuilder $filterBuilder, | ||
ScopeConfigInterface $scopeConfig, | ||
StoreManagerInterface $storeManager, | ||
CategoryRepositoryInterface $categoryRepositoryInterface, | ||
CategoryInterface $categoryInterface | ||
) { | ||
$this->categoryRepository = $categoryRepository; | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
$this->filterBuilder = $filterBuilder; | ||
$this->scopeConfig = $scopeConfig; | ||
$this->storeManager = $storeManager; | ||
$this->categoryInterface = $categoryInterface; | ||
$this->categoryRepositoryInterface = $categoryRepositoryInterface; | ||
} | ||
|
||
public function getList(SearchCriteriaInterface $searchCriteria) | ||
{ | ||
$searchResult = $this->categoryRepository->getList($searchCriteria); | ||
$baseUrl = $this->storeManager->getStore()->getBaseUrl(); | ||
$category_url_suffix = $this->scopeConfig->getValue( | ||
'catalog/seo/category_url_suffix', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||
); | ||
|
||
foreach ($searchResult->getItems() as $category) { | ||
$categoryData = $category->getData(); | ||
$fullPath = $baseUrl . $categoryData['url_path'] . $category_url_suffix; | ||
$extensionAttributes = $category->getExtensionAttributes(); | ||
$extensionAttributes->setUrlFull($fullPath); | ||
} | ||
|
||
return $searchResult; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<head> | ||
<!-- For hyva themes, jQuery can't be used among other modifications. | ||
In that case we use a different JS --> | ||
<remove src="Doofinder_Feed::js/df_add_to_cart.js"/> | ||
<script src="Doofinder_Feed::js/df_add_to_cart_hyva.js"/> | ||
</head> | ||
<body> | ||
<referenceBlock name="head.additional"> | ||
<block | ||
class="Doofinder\Feed\Block\Display\Layer" | ||
name="doofinderfeed_display_layer" | ||
as="doofinderfeed.display.layer" | ||
template="Doofinder_Feed::display/layer.phtml" | ||
ifconfig="doofinder_config_config/doofinder_layer/doofinder_layer_enabled" | ||
after="-"/> | ||
</referenceBlock> | ||
</body> | ||
</page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class DoofinderAddToCartError extends Error { | ||
constructor(reason, status = "") { | ||
const message = | ||
"Error adding an item to the cart. Reason: " + | ||
reason + | ||
". Status code: " + | ||
status; | ||
super(message); | ||
this.name = "DoofinderAddToCartError"; | ||
} | ||
} | ||
|
||
document.addEventListener("doofinder.cart.add", function (event) { | ||
const { item_id, amount, statusPromise } = event.detail; | ||
addToCart(item_id, amount, statusPromise); | ||
}); | ||
|
||
function addToCart(item_id, amount, statusPromise) { | ||
amount = !amount ? 1 : parseInt(amount); | ||
item_id = parseInt(item_id); | ||
|
||
const params = new URLSearchParams({ | ||
form_key: hyva.getFormKey(), | ||
id: item_id, | ||
qty: amount, | ||
}); | ||
|
||
fetch(`${BASE_URL}doofinderfeed/Product/AddToCart?${params.toString()}`, { | ||
method: "POST", | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
return response.text().then((error) => { | ||
throw new Error(error); | ||
}); | ||
} | ||
|
||
return response.json(); | ||
}) | ||
.then((data) => { | ||
if (data.product_url) { | ||
statusPromise.reject( | ||
new DoofinderAddToCartError( | ||
"Configurable product. Redirecting to product URL", | ||
200, | ||
), | ||
); | ||
window.location = data.product_url; | ||
return; | ||
} | ||
|
||
statusPromise.resolve( | ||
"The item has been successfully added to the cart.", | ||
); | ||
dispatchEvent(new Event("reload-customer-section-data")); | ||
}) | ||
.catch((error) => { | ||
statusPromise.reject(new DoofinderAddToCartError(error)); | ||
}); | ||
} |