Skip to content

Commit

Permalink
fix autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienLavorel committed May 12, 2019
1 parent 82a221b commit 8103d65
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
27 changes: 27 additions & 0 deletions Block/Checkout/AlgoliaPlaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

use Magento\Framework\View\Element\Template;

/**
* Class AlgoliaPlaces
*
* @package Lavoweb\AlgoliaPlaces\Block\Checkout
*/
class AlgoliaPlaces extends Template
{
const XML_PATH_ENABLED = 'sales/algolia_places/enabled';
Expand All @@ -13,6 +18,13 @@ class AlgoliaPlaces extends Template
/** @var \Magento\Framework\App\Config\ScopeConfigInterface */
protected $scopeConfig;

/**
* AlgoliaPlaces constructor.
*
* @param Template\Context $context
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param array $data
*/
public function __construct(
Template\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
Expand All @@ -23,16 +35,31 @@ public function __construct(
parent::__construct($context, $data);
}

/**
* Is Enabled
*
* @return boolean
*/
public function isEnabled()
{
return $this->scopeConfig->getValue(self::XML_PATH_ENABLED, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* Get App Id
*
* @return string
*/
public function getAppId()
{
return $this->scopeConfig->getValue(self::XML_PATH_APP_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* Get Api Key
*
* @return string
*/
public function getApiKey()
{
return $this->scopeConfig->getValue(self::XML_PATH_API_KEY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
Expand Down
24 changes: 23 additions & 1 deletion Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Magento\Checkout\Model\ConfigProviderInterface;

/**
* Class SampleConfigProvider
* Class ConfigProvider
*
* @package Lavoweb\AlgoliaPlaces\Model
*/
class ConfigProvider implements ConfigProviderInterface
{
Expand All @@ -16,23 +18,43 @@ class ConfigProvider implements ConfigProviderInterface
/** @var \Magento\Framework\App\Config\ScopeConfigInterface */
protected $scopeConfig;

/**
* ConfigProvider constructor.
*
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
)
{
$this->scopeConfig = $scopeConfig;
}

/**
* Is Enabled
*
* @return boolean
*/
public function isEnabled()
{
return $this->scopeConfig->getValue(self::XML_PATH_ENABLED, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* Get App Id
*
* @return string
*/
public function getAppId()
{
return $this->scopeConfig->getValue(self::XML_PATH_APP_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* Get Api Key
*
* @return string
*/
public function getApiKey()
{
return $this->scopeConfig->getValue(self::XML_PATH_API_KEY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
Expand Down
2 changes: 1 addition & 1 deletion etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<type name="Magento\Checkout\Model\CompositeConfigProvider">
<arguments>
<argument name="configProviders" xsi:type="array">
<item name="algolia_places_config_provider" xsi:type="object">Lavoweb\AlgoliaPlaces\Model\ConfigProvider</item>
<item name="algolia_places_config_provider" xsi:type="object">\Lavoweb\AlgoliaPlaces\Model\ConfigProvider</item>
</argument>
</arguments>
</type>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Lavoweb\AlgoliaPlaces\Block\Checkout\AlgoliaPlaces" name="checkout.algoliaplace" template="LavoWeb_AlgoliaPlaces::algoliaplaces.phtml" after="-" cacheable="false" />
<block class="\Lavoweb\AlgoliaPlaces\Block\Checkout\AlgoliaPlaces" name="checkout.algoliaplace" template="LavoWeb_AlgoliaPlaces::algoliaplaces.phtml" after="-" cacheable="false" />
</referenceContainer>
</body>
</page>
2 changes: 1 addition & 1 deletion view/frontend/templates/algoliaplaces.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/** @var Lavoweb\AlgoliaPlaces\Block\Checkout\AlgoliaPlaces $block */
/** @var \Lavoweb\AlgoliaPlaces\Block\Checkout\AlgoliaPlaces $block */
if ($block->isEnabled()) :
?><script type="text/javascript">
require(['algoliaplaces', 'jquery'], function(places, jQuery){
Expand Down

0 comments on commit 8103d65

Please sign in to comment.