-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 6979381
Showing
8 changed files
with
182 additions
and
0 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,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace ProxiBlue\HyvaSmileAutocompleteAddToCart\Plugin; | ||
|
||
use Magento\Checkout\Helper\Cart as CartHelper; | ||
|
||
class ItemFactory | ||
{ | ||
|
||
/** | ||
* @var CartHelper | ||
*/ | ||
protected $cartHelper; | ||
|
||
/** | ||
* @param CartHelper $cartHelper | ||
*/ | ||
public function __construct( | ||
CartHelper $cartHelper | ||
) { | ||
$this->cartHelper = $cartHelper; | ||
} | ||
|
||
/** | ||
* Inject thw add to cart url here | ||
* | ||
* @param \Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\ItemFactory $subject | ||
* @param callable $proceed | ||
* @param $data | ||
* @return mixed | ||
*/ | ||
public function aroundCreate(\Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\ItemFactory $subject, callable $proceed, $data) | ||
{ | ||
if ($data['product'] | ||
&& $data['product']->isSaleable() | ||
&& $data['product']->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) { | ||
$data['add_url'] = $this->cartHelper->getAddUrl($data['product'], ['useUencPlaceholder'=>true]); | ||
$data['type'] = 'product_add_to_cart'; | ||
} | ||
return $proceed($data); | ||
} | ||
} |
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,28 @@ | ||
{ | ||
"name": "proxi-blue/hyva-smile-autocomplete-add-to-cart", | ||
"version": "1.0.0", | ||
"description": "Add To Cart inline in autocomplete", | ||
"type": "magento2-module", | ||
"require": { | ||
"magento/framework": "*", | ||
"hyva-themes/magento2-smile-elasticsuite": "~1.1", | ||
"hyva-themes/magento2-default-theme": ">1.1.9" | ||
}, | ||
"license": [ | ||
"Massachusetts Institute of Technology License (MITL)" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Lucas van Staden", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"files": [ | ||
"registration.php" | ||
], | ||
"psr-4": { | ||
"ProxiBlue\\HyvaSmileAutocompleteAddToCart\\": "" | ||
} | ||
} | ||
} |
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,7 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\ItemFactory"> | ||
<plugin name="proxiblue_hyvasmileautocompleteaddtocart_itemfactory" | ||
type="ProxiBlue\HyvaSmileAutocompleteAddToCart\Plugin\ItemFactory"/> | ||
</type> | ||
</config> |
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,9 @@ | ||
<?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="ProxiBlue_HyvaSmileAutocompleteAddToCart"> | ||
<sequence> | ||
<module name="Hyva_SmileElasticsuite"/> | ||
</sequence> | ||
</module> | ||
</config> |
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,25 @@ | ||
# Autocomplete Add To Cart Button | ||
|
||
## Introduction | ||
|
||
Place an add to cart button on Autocomplete for saleable simple products | ||
|
||
## Requirements | ||
|
||
* Hyva Theme for Magento | ||
* Smile ElasticSuite Search with Autocomplete enabled | ||
* Hyva Smile Compatibility module | ||
|
||
## Install | ||
|
||
* composer config repositories.github.repo.repman.io composer https://github.repo.repman.io | ||
* composer require proxi-blue/hyva-smile-autocomplete-add-to-cart | ||
* ./bin/magento setup:upgrade | ||
* ./bin/magento setup:di:compile | ||
|
||
## Configuration | ||
|
||
None, once installed, button will be added to all simple products | ||
|
||
|
||
|
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,5 @@ | ||
<?php | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'ProxiBlue_HyvaSmileAutocompleteAddToCart', __DIR__); |
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,16 @@ | ||
<?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"> | ||
<body> | ||
<referenceBlock name="top.search" remove="true" /> | ||
<referenceBlock name="header-search" class="Smile\ElasticsuiteCore\Block\Search\Form\Autocomplete" > | ||
<arguments> | ||
<argument name="rendererList" xsi:type="array"> | ||
<item name="product_add_to_cart" xsi:type="array"> | ||
<item name="title" xsi:type="string" translate="true">Products</item> | ||
<item name="template" xsi:type="string">ProxiBlue_HyvaSmileAutocompleteAddToCart::catalog/autocomplete/product_add_to_cart.phtml</item> | ||
</item> | ||
</argument> | ||
</arguments> | ||
</referenceBlock> | ||
</body> | ||
</page> |
50 changes: 50 additions & 0 deletions
50
view/frontend/templates/catalog/autocomplete/product_add_to_cart.phtml
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,50 @@ | ||
<?php | ||
/** | ||
* Hyvä Themes - https://hyva.io | ||
* Copyright © Hyvä Themes 2020-present. All rights reserved. | ||
* This product is licensed per Magento install | ||
* See https://hyva.io/license | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Hyva\Theme\Model\ViewModelRegistry; | ||
use Hyva\Theme\ViewModel\HeroiconsOutline; | ||
|
||
// phpcs:disable Generic.Files.LineLength.TooLong | ||
|
||
/** @var ViewModelRegistry $viewModels */ | ||
/** @var Escaper $escaper */ | ||
|
||
/** @var HeroiconsOutline $heroiconsOutline */ | ||
$heroiconsOutline = $viewModels->require(HeroiconsOutline::class); | ||
|
||
?> | ||
|
||
<template x-if="searchResult.type == 'product_add_to_cart'"> | ||
<a class="w-full block" :href="searchResult.url" :title="searchResult.title"> | ||
<div class="grid grid-cols-5 gap-4 p-3"> | ||
<div class="col-span-1"> | ||
<img :src="searchResult.image" class="inline-block" /> | ||
</div> | ||
<div class="col-span-2"> | ||
<span class="text-sm" x-text="searchResult.title"></span> | ||
<span class="text-sm font-bold" x-html="searchResult.price"></span> | ||
</div> | ||
<div class="col-span-2 content-end items-end"> | ||
<form method="post" | ||
x-bind:action="searchResult.add_url"> | ||
<?= /** @noEscape */ $block->getBlockHtml('formkey') ?> | ||
<button class="btn btn-primary" | ||
aria-label="<?= $escaper->escapeHtmlAttr(__('Add to Cart')) ?>" | ||
> | ||
<?= $heroiconsOutline->shoppingCartHtml("h-6 w-6 border-current inline", 25, 25) ?> | ||
<span class="product-addtocart-button ml-2 inline"> | ||
<?= $escaper->escapeHtml(__('Add to Cart')) ?> | ||
</span> | ||
</button> | ||
</form> | ||
</div> | ||
</div> | ||
</a> | ||
</template> |