Skip to content

Commit

Permalink
feat: Resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmolinacano committed Nov 18, 2024
2 parents 57a0dd2 + 3ff6250 commit b6a0a25
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 10 deletions.
18 changes: 18 additions & 0 deletions Api/CategoryListInterface.php
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;
}
4 changes: 3 additions & 1 deletion Controller/Product/AddToCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function execute()

$params = new DataObject($params);
$result = $quote->addProduct($product, $params);
$resultJson = $this->resultJsonFactory->create();

if (is_a($result, QuoteItem::class)) {
//Update totals
Expand All @@ -90,12 +91,13 @@ public function execute()
$quote->collectTotals();
$this->cartRepository->save($quote);
$session->replaceQuote($quote)->unsLastRealOrderId();

return $resultJson->setData(['success' => true]);
} else {
$this->logger->info("This product is variable, return the url");
$product_url = $product->getProductUrl();
$this->logger->info("Product url: ", ["product_url" => $product_url]);

$resultJson = $this->resultJsonFactory->create();
return $resultJson->setData(['product_url' => $product_url]);
}
}
Expand Down
Empty file modified Cron/Processor.php
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions Helper/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Catalog\Model\Product\Type as ProductType;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableType;
use Magento\Downloadable\Model\Product\Type as DownloadableType;
use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedType;
Expand Down Expand Up @@ -195,6 +196,11 @@ private function getMinimumComplexProductPrice($product, $usedProds, $type)
$minimum_price = null;
$minimum_variant = null;

// To exclude disabled variants from the calculations
$usedProds = array_filter($usedProds, function($child) {
return Status::STATUS_ENABLED === (int)$child->getStatus();
});

/*
We identify the variant with the minimum final price (or price), and
that is the one that is used to obtain the requested price for the
Expand Down
2 changes: 1 addition & 1 deletion Helper/StoreConfig.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
class StoreConfig extends AbstractHelper
{
public const CRON_DISABLED_VALUE = 'everyday';
public const CRON_DISABLED_VALUE = '0 0 * * *';
/**
* URL to make the doofinder requests
*/
Expand Down
61 changes: 61 additions & 0 deletions Model/CategoryListRepository.php
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;
}

}
11 changes: 5 additions & 6 deletions Model/ResourceModel/ChangedItem.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace Doofinder\Feed\Model\ResourceModel;

use Magento\Framework\Model\ResourceModel\Db\AbstractDB;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;

/**
* The resource model of product change trace.
*/
class ChangedItem extends AbstractDB
class ChangedItem extends AbstractDb
{
/**
* Holds the name of the table responsible for storing identities of deleted products.
Expand All @@ -17,16 +17,15 @@ class ChangedItem extends AbstractDB
*/
public const TABLE_NAME = 'doofinder_feed_changed_item';

public const ENTITY_ID = 'entity_id';

/**
* Initializes resource model.
*
* @return void
*/
protected function _construct()
{
$this->_init(
self::TABLE_NAME,
'entity_id'
);
$this->_init(self::TABLE_NAME, self::ENTITY_ID);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doofinder/doofinder-magento2",
"version": "0.14.12",
"version": "1.0.0",
"description": "Doofinder module for Magento 2",
"type": "magento2-module",
"require": {
Expand Down
Empty file modified etc/config.xml
100644 → 100755
Empty file.
Empty file modified etc/db_schema.xml
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions etc/di.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<preference for="Doofinder\Feed\Api\Data\ChangedItemInterface" type="Doofinder\Feed\Model\ChangedItem"/>
<preference for="Doofinder\Feed\Api\Data\ChangedItemSearchResultsInterface" type="Doofinder\Feed\Model\ChangedItemSearchResults"/>
<preference for="Doofinder\Feed\Api\ProductRepositoryInterface" type="Doofinder\Feed\Model\ProductRepository" />
<preference for="Doofinder\Feed\Api\CategoryListInterface" type="Doofinder\Feed\Model\CategoryListRepository" />
<preference for="Doofinder\Feed\Api\ModuleDataInterface" type="Doofinder\Feed\Model\ModuleData" />
<preference for="Doofinder\Feed\Api\SingleScriptInterface" type="Doofinder\Feed\Model\SingleScript" />
</config>
3 changes: 3 additions & 0 deletions etc/extension_attributes.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
<attribute code="price" type="float"/>
<attribute code="special_price" type="float"/>
</extension_attributes>
<extension_attributes for="Magento\Catalog\Api\Data\CategoryInterface">
<attribute code="url_full" type="string"/>
</extension_attributes>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Doofinder_Feed" setup_version="0.14.12">
<module name="Doofinder_Feed" setup_version="1.0.0">
<sequence>
<module name="Magento_Integration" />
</sequence>
Expand Down
6 changes: 6 additions & 0 deletions etc/webapi.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<resource ref="Magento_Catalog::products"/>
</resources>
</route>
<route url="/V1/custom/categories" method="GET">
<service class="Doofinder\Feed\Api\CategoryListInterface" method="getList"/>
<resources>
<resource ref="Magento_Catalog::categories" />
</resources>
</route>
<route url="/V1/doofinder/single-script" method="GET">
<service class="Doofinder\Feed\Api\SingleScriptInterface" method="replace"/>
<resources>
Expand Down
21 changes: 21 additions & 0 deletions view/frontend/layout/hyva_default.xml
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>
60 changes: 60 additions & 0 deletions view/frontend/web/js/df_add_to_cart_hyva.js
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));
});
}

0 comments on commit b6a0a25

Please sign in to comment.