Skip to content

Commit

Permalink
[M2M-17] Pass negation of isUserNotAllowSaveCookie() directly to the …
Browse files Browse the repository at this point in the history
…allowCookies parameter for the flowbox script's init function
  • Loading branch information
drazulay committed Oct 8, 2021
1 parent 4878141 commit 075ee83
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
22 changes: 17 additions & 5 deletions Block/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ abstract class Base extends \Magento\Framework\View\Element\Template

const FLOW_TYPE_DYNAMIC_TAG = 'dynamic-tag';

/**
* @var \Magento\Framework\Encryption\EncryptorInterface
*/
private $encryptor;
private \Magento\Framework\Encryption\EncryptorInterface $encryptor;

private \Magento\Cookie\Helper\Cookie $cookie;

/**
* Base constructor.
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Cookie\Helper\Cookie $cookie
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Cookie\Helper\Cookie $cookie,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
array $data = []
) {
\Magento\Framework\View\Element\Template::__construct($context, $data);
parent::__construct($context, $data);
$this->cookie = $cookie;
$this->encryptor = $encryptor;
}

Expand Down Expand Up @@ -83,6 +85,16 @@ public function getJsConfig(): string
return $this->toJson(['flowbox']);
}

/**
* Checks whether user is allowed to save cookies.
*
* @return bool
*/
protected function isUserAllowSaveCookies(): bool
{
return false === $this->cookie->isUserNotAllowSaveCookie();
}

/**
* Prepare configuration for javascript component
*
Expand Down
14 changes: 7 additions & 7 deletions Block/Checkout/Onepage/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@

class Success extends \Itonomy\Flowbox\Block\Base
{
/**
* @var \Magento\Checkout\Model\Session
*/
private $checkoutSession;
private \Magento\Checkout\Model\Session $checkoutSession;

/**
* Success constructor.
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Magento\Cookie\Helper\Cookie $cookie
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Magento\Cookie\Helper\Cookie $cookie,
\Magento\Checkout\Model\Session $checkoutSession,
array $data = []
) {
parent::__construct($context, $encryptor, $data);
parent::__construct($context, $cookie, $encryptor, $data);
$this->checkoutSession = $checkoutSession;
}

Expand All @@ -40,8 +39,9 @@ protected function prepareConfig(): void
$order = $this->checkoutSession->getLastRealOrder();

$this->setData('flowbox', [
'debug' => $this->isDebugJavaScript(),
'allowCookies' => $this->isUserAllowSaveCookies(),
'apiKey' => (string) $this->getApiKey(),
'debug' => $this->isDebugJavaScript(),
'orderId' => \ltrim($order->getIncrementId(), '#'),
'products' => \array_map(
function ($item) {
Expand Down Expand Up @@ -80,4 +80,4 @@ protected function getAllVisibleItems($order)
}
return $items;
}
}
}
16 changes: 7 additions & 9 deletions Block/Widget/Flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,28 @@ class Flow extends \Itonomy\Flowbox\Block\Base implements \Magento\Widget\Block\
{
protected $_template = "widget/flow.phtml";

/**
* @var \Magento\Catalog\Api\ProductRepositoryInterface
*/
private $productRepository;
/**
* @var \Magento\Framework\Api\SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;
private \Magento\Catalog\Api\ProductRepositoryInterface $productRepository;

private \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder;

/**
* Flow constructor.
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Magento\Cookie\Helper\Cookie $cookie
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Cookie\Helper\Cookie $cookie,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
array $data = []
) {
parent::__construct($context, $encryptor, $data);
parent::__construct($context, $cookie, $encryptor, $data);
$this->productRepository = $productRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}
Expand All @@ -48,6 +45,7 @@ protected function prepareConfig(): void
try {
$flow = $this->getFlow();
$config = [
'allowCookies' => $this->isUserAllowSaveCookies(),
'debug' => $this->isDebugJavaScript(),
'flow' => $flow,
'key' => $this->escapeHtml((string) $this->getData('key')),
Expand Down
3 changes: 2 additions & 1 deletion view/frontend/web/js/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ define([
], function(Component, _, ko, $, fb) {
'use strict';

var flowKeys = ['apiKey', 'products', 'orderId'];
var flowKeys = ['allowCookies', 'apiKey', 'products', 'orderId'];

return Component.extend({
defaults: {
flowbox: {
allowCookies: true,
}
},

Expand Down
2 changes: 2 additions & 0 deletions view/frontend/web/js/flowbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define([
'use strict';

var flowKeys = [
'allowCookies',
'container',
'key',
'locale',
Expand All @@ -26,6 +27,7 @@ define([
return Component.extend({
defaults: {
flowbox: {
allowCookies: true,
lazyload: true,
showTagBar: false,
tags: [],
Expand Down

0 comments on commit 075ee83

Please sign in to comment.