Skip to content

Commit

Permalink
Merge pull request #4 from humanelement/OM2-206
Browse files Browse the repository at this point in the history
OM2-206 Add ScrollTop Functionality & Other Improvements
  • Loading branch information
floorz authored Oct 1, 2019
2 parents c58e258 + aa8c016 commit f3fa85a
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 208 deletions.
67 changes: 0 additions & 67 deletions Block/Sidebar.php

This file was deleted.

35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# module-mini-cart-auto-open
Magento 2 Mini Cart Auto Open Extension
# HumanElement_MiniCartAutoOpen

assuming your project has access to the human element composer repo
## Authors

Ajay Khampariya <ajay@human-element.com> :bowtie:
Seth Daugherty <sdaugherty@human-element.com>
Nate Shiff <nshiff@human-element.com>


Assuming your project has access to the human element composer repo

## Installing/Updating

to install:

Expand All @@ -14,3 +22,24 @@ to update:
```
composer update human-element/module-mini-cart-auto-open
```

## Configuration:

Stores > Settings > Configuration > Sales > Checkout > Shopping Cart Sidebar:

Automatically Open Minicart After Adding Product to Cart
- Set to "Yes" to have the minicart automatically open after adding an item to the cart

Timeout in Seconds (0-10) Before Automatically Closing Sidebar
- Depends on auto open of minicart being enabled
- Set the number of seconds the minicart should stay open before closing

Scroll to Top of Page After Adding Product to Cart
- Depends on auto open of minicart being enabled
- Set to "Yes" to have the browser automatically scroll to top of page after adding item to cart


## Documentation:

- Can auto open the minicart after adding product to cart
- Can scroll page to top after adding product to cart
102 changes: 102 additions & 0 deletions ViewModel/Sidebar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Human Element Inc.
*
* @package HumanElement_MiniCartAutoOpen
* @copyright Copyright (c) 2017 Human Element Inc. (https://www.human-element.com)
*/

namespace HumanElement\MiniCartAutoOpen\ViewModel;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Store\Model\ScopeInterface;

/**
* Cart sidebar block
*/
class Sidebar implements ArgumentInterface
{
/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;

/**
* Sidebar constructor.
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

/**
* Xml path to checkout sidebar auto open value
*/
const XML_PATH_CHECKOUT_SIDEBAR_AUTO_OPEN = 'checkout/sidebar/auto_open';

/**
* Xml path to checkout sidebar auto open timeout value
*/
const XML_PATH_CHECKOUT_SIDEBAR_AUTO_OPEN_TIMEOUT = 'checkout/sidebar/auto_open_timeout';

/**
* Xml path to checkout sidebar scroll top value
*/
const XML_PATH_CHECKOUT_SIDEBAR_SCROLL_TOP = 'checkout/sidebar/scroll_top';

/**
* Returns minicart config
*
* @return array
*/
public function getConfig()
{
return [
'canAutoOpen' => $this->getMiniCartCanAutoOpen(),
'autoOpenTimeout' => $this->getMiniCartAutoOpenTimeout(),
'canScrollTop' => $this->getMiniCartScrollTop(),
];
}

/**
* Return whether the minicart can auto open
*
* @return int
*/
protected function getMiniCartCanAutoOpen()
{
return (bool)$this->scopeConfig->isSetFlag(
self::XML_PATH_CHECKOUT_SIDEBAR_AUTO_OPEN,
ScopeInterface::SCOPE_STORE
);
}

/**
* Return whether the minicart can auto open
*
* @return int
*/
protected function getMiniCartAutoOpenTimeout()
{
return (int)$this->scopeConfig->getValue(
self::XML_PATH_CHECKOUT_SIDEBAR_AUTO_OPEN_TIMEOUT,
ScopeInterface::SCOPE_STORE
);
}

/**
* Return whether to scroll to top of page after adding product to cart
*
* @return int
*/
protected function getMiniCartScrollTop()
{
return (bool)$this->scopeConfig->isSetFlag(
self::XML_PATH_CHECKOUT_SIDEBAR_SCROLL_TOP,
ScopeInterface::SCOPE_STORE
);
}
}
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "human-element/module-mini-cart-auto-open",
"description": "Magento 2 Human-Element Mini Cart Auto Open Extension",
"type": "magento2-module",
"version": "2.1.0",
"version": "2.2.0",
"license": [
"GPL-3.0"
],
Expand All @@ -14,6 +14,10 @@
{
"email": "sdaugherty@human-element.com",
"name": "Seth Daugherty"
},
{
"email": "ajay@human-element.com",
"name": "AK"
}
],
"require": {
Expand Down
12 changes: 10 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@
<system>
<section id="checkout">
<group id="sidebar">
<field id="auto_open" translate="label" type="select" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<field id="auto_open" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Automatically Open Minicart After Adding Product to Cart</label>
<comment>Depends on theme and ajax add to cart being enabled</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="auto_open_timeout" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<field id="auto_open_timeout" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Timeout in Seconds (0-10) Before Automatically Closing Sidebar</label>
<depends>
<field id="auto_open">1</field>
</depends>
<validate>validate-digits validate-digits-range digits-range-0-10</validate>
</field>
<field id="scroll_top" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Scroll to Top of Page After Adding Product to Cart</label>
<comment>After adding product to cart, auto scrolls user to top of page to see their mini cart</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="auto_open">1</field>
</depends>
</field>
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<sidebar>
<auto_open>0</auto_open>
<auto_open_timeout>3</auto_open_timeout>
<scroll_top>0</scroll_top>
</sidebar>
</checkout>
</default>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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="HumanElement_MiniCartAutoOpen" setup_version="2.1.0">
<module name="HumanElement_MiniCartAutoOpen" setup_version="2.2.0">
<sequence>
<module name="Magento_Catalog"/>
</sequence>
Expand Down
7 changes: 6 additions & 1 deletion view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="minicart.addons">
<block class="HumanElement\MiniCartAutoOpen\Block\Sidebar" name="minicart.autoopen" template="HumanElement_MiniCartAutoOpen::minicart_open.phtml"/>
<block name="minicart.autoopen">
<arguments>
<argument name="template" xsi:type="string">HumanElement_MiniCartAutoOpen::minicart_open.phtml</argument>
<argument name="view_model" xsi:type="object">HumanElement\MiniCartAutoOpen\ViewModel\Sidebar</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
7 changes: 6 additions & 1 deletion view/frontend/templates/minicart_open.phtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php
/** @var \HumanElement\MinicartAutoOpen\ViewModel\Sidebar $viewModel */
$viewModel = $block->getViewModel();
?>

<script type="text/x-magento-init">
{
"[data-block='minicart']" : {
"HumanElement_MiniCartAutoOpen/js/view/minicart_open" : <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getConfig()); ?>
"HumanElement_MiniCartAutoOpen/js/view/minicart_open" : <?php /* @escapeNotVerified */ echo \Zend_Json::encode($viewModel->getConfig()); ?>
}
}
</script>
Loading

0 comments on commit f3fa85a

Please sign in to comment.