-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from monsoonconsulting/dev
Merge dev into main
- Loading branch information
Showing
9 changed files
with
193 additions
and
3 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,63 @@ | ||
<?php | ||
/** | ||
* Copyright © Monsoon Consulting. All rights reserved. | ||
* See LICENSE_MONSOON.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Monsoon\HyvaAjaxAddToCart\Block; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
use Monsoon\HyvaAjaxAddToCart\Model\ConfigInterface; | ||
|
||
/** | ||
* Class AddToCart | ||
*/ | ||
class AddToCart extends Template | ||
{ | ||
/** | ||
* @var ConfigInterface | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* Upsell block contructor | ||
* | ||
* @param Template\Context $context | ||
* @param ConfigInterface $config | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
ConfigInterface $config, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
|
||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Render block HTML | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml(): string | ||
{ | ||
if (!$this->getTemplate() || !$this->config->isAjaxAddToCartEnabled()) { | ||
return ''; | ||
} | ||
return $this->fetchView($this->getTemplateFile()); | ||
} | ||
|
||
/** | ||
* Get Ajax Add To Cart Delay (in milliseconds) | ||
* | ||
* @return string | ||
*/ | ||
public function getDelay(): string | ||
{ | ||
return $this->config->getAjaxAddToCartDelay(); | ||
} | ||
} |
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,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Monsoon Consulting. All rights reserved. | ||
* See LICENSE_MONSOON.txt for license details | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Monsoon\HyvaAjaxAddToCart\Model; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Class Config | ||
*/ | ||
class Config implements ConfigInterface | ||
{ | ||
/** @var ScopeConfigInterface */ | ||
private ScopeConfigInterface $scopeConfig; | ||
|
||
/** | ||
* @param ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
|
||
/** | ||
* Is the AJAX add to cart option enabled? | ||
* | ||
* @param null|int|string $scopeCode | ||
* @return bool | ||
*/ | ||
public function isAjaxAddToCartEnabled($scopeCode = null): bool | ||
{ | ||
return (bool)$this->scopeConfig->isSetFlag( | ||
self::XML_PATH_ENABLE_AJAX_ADD_TO_CART, | ||
ScopeInterface::SCOPE_STORE, | ||
$scopeCode | ||
); | ||
} | ||
|
||
/** | ||
* Get Ajax Add To Cart Delay | ||
* | ||
* @param null|int|string $scopeCode | ||
* @return string | ||
*/ | ||
public function getAjaxAddToCartDelay($scopeCode = null): string | ||
{ | ||
return (string)$this->scopeConfig->getValue( | ||
self::XML_PATH_AJAX_ADD_TO_CART_DELAY, | ||
ScopeInterface::SCOPE_STORE, | ||
$scopeCode | ||
); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
/** | ||
* Copyright © Monsoon Consulting. All rights reserved. | ||
* See LICENSE_MONSOON.txt for license details | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Monsoon\HyvaAjaxAddToCart\Model; | ||
|
||
/** | ||
* Interface ConfigInterface | ||
*/ | ||
interface ConfigInterface | ||
{ | ||
public const XML_PATH_ENABLE_AJAX_ADD_TO_CART = 'checkout/options/enable_ajax_add_to_cart'; | ||
public const XML_PATH_AJAX_ADD_TO_CART_DELAY = 'checkout/options/ajax_add_to_cart_delay'; | ||
|
||
/** | ||
* Is the AJAX add to cart option enabled? | ||
* | ||
* @param null|int|string $scopeCode | ||
* @return bool | ||
*/ | ||
|
||
public function isAjaxAddToCartEnabled($scopeCode = null): bool; | ||
|
||
/** | ||
* Get Ajax Add To Cart Delay | ||
* | ||
* @param null|int|string $scopeCode | ||
* @return string | ||
*/ | ||
public function getAjaxAddToCartDelay($scopeCode = null): string; | ||
} |
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,11 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Monsoon Consulting. All rights reserved. | ||
* See LICENSE_MONSOON.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference for="Monsoon\HyvaAjaxAddToCart\Model\ConfigInterface" | ||
type="Monsoon\HyvaAjaxAddToCart\Model\Config" /> | ||
</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
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