Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
ProxiBlue committed Apr 1, 2022
0 parents commit 6979381
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Plugin/ItemFactory.php
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);
}
}
28 changes: 28 additions & 0 deletions composer.json
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\\": ""
}
}
}
7 changes: 7 additions & 0 deletions etc/frontend/di.xml
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>
9 changes: 9 additions & 0 deletions etc/module.xml
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>
25 changes: 25 additions & 0 deletions readme.md
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



5 changes: 5 additions & 0 deletions registration.php
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__);
16 changes: 16 additions & 0 deletions view/frontend/layout/hyva_default.xml
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>
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>

0 comments on commit 6979381

Please sign in to comment.