Skip to content

Commit ebe6597

Browse files
Merge pull request #20 from Itonomy/release/1.4.6
Release/1.4.6
2 parents 0d36faf + 312915d commit ebe6597

File tree

26 files changed

+293
-89
lines changed

26 files changed

+293
-89
lines changed

src/Block/Base.php renamed to Block/Base.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@ abstract class Base extends \Magento\Framework\View\Element\Template
2121

2222
const FLOW_TYPE_DYNAMIC_TAG = 'dynamic-tag';
2323

24-
/**
25-
* @var \Magento\Framework\Encryption\EncryptorInterface
26-
*/
27-
private $encryptor;
24+
private \Magento\Framework\Encryption\EncryptorInterface $encryptor;
25+
26+
private \Magento\Cookie\Helper\Cookie $cookie;
2827

2928
/**
3029
* Base constructor.
3130
* @param \Magento\Framework\View\Element\Template\Context $context
31+
* @param \Magento\Cookie\Helper\Cookie $cookie
3232
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
3333
* @param array $data
3434
*/
3535
public function __construct(
3636
\Magento\Framework\View\Element\Template\Context $context,
37+
\Magento\Cookie\Helper\Cookie $cookie,
3738
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
3839
array $data = []
3940
) {
40-
\Magento\Framework\View\Element\Template::__construct($context, $data);
41+
parent::__construct($context, $data);
42+
$this->cookie = $cookie;
4143
$this->encryptor = $encryptor;
4244
}
4345

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

88+
/**
89+
* Checks whether user is allowed to save cookies.
90+
*
91+
* @return bool
92+
*/
93+
protected function isUserAllowSaveCookies(): bool
94+
{
95+
return false === $this->cookie->isUserNotAllowSaveCookie();
96+
}
97+
8698
/**
8799
* Prepare configuration for javascript component
88100
*

src/Block/Checkout/Onepage/Success.php renamed to Block/Checkout/Onepage/Success.php

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,58 @@
1-
<?php declare(strict_types=1);
1+
<?php
22

33
/**
44
* Copyright © Itonomy BV. All rights reserved.
55
* See LICENSE.md for license details.
66
*/
7-
87
namespace Itonomy\Flowbox\Block\Checkout\Onepage;
98

9+
use Itonomy\Flowbox\Helper\Data;
10+
use Magento\Checkout\Model\Session;
11+
use Magento\Cookie\Helper\Cookie;
12+
use Magento\Framework\Encryption\EncryptorInterface;
13+
use Magento\Framework\View\Element\Template\Context;
14+
use Magento\Catalog\Model\ProductRepository;
15+
1016
class Success extends \Itonomy\Flowbox\Block\Base
1117
{
1218
/**
13-
* @var \Magento\Checkout\Model\Session
19+
* @var Session
1420
*/
1521
private $checkoutSession;
1622

23+
/**
24+
* @var Data
25+
*/
26+
private $helper;
27+
28+
/**
29+
* @var ProductRepository
30+
*/
31+
private $productRepository;
32+
1733
/**
1834
* Success constructor.
19-
* @param \Magento\Framework\View\Element\Template\Context $context
20-
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
21-
* @param \Magento\Checkout\Model\Session $checkoutSession
35+
* @param Context $context
36+
* @param EncryptorInterface $encryptor
37+
* @param Cookie $cookie
38+
* @param Session $checkoutSession
39+
* @param ProductRepository $productRepository
40+
* @param Data $helper
2241
* @param array $data
2342
*/
2443
public function __construct(
25-
\Magento\Framework\View\Element\Template\Context $context,
26-
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
27-
\Magento\Checkout\Model\Session $checkoutSession,
44+
Context $context,
45+
EncryptorInterface $encryptor,
46+
Cookie $cookie,
47+
Session $checkoutSession,
48+
ProductRepository $productRepository,
49+
Data $helper,
2850
array $data = []
2951
) {
30-
parent::__construct($context, $encryptor, $data);
52+
parent::__construct($context, $cookie, $encryptor, $data);
53+
$this->helper = $helper;
3154
$this->checkoutSession = $checkoutSession;
55+
$this->productRepository = $productRepository;
3256
}
3357

3458
/**
@@ -39,14 +63,17 @@ protected function prepareConfig(): void
3963
try {
4064
$order = $this->checkoutSession->getLastRealOrder();
4165

66+
4267
$this->setData('flowbox', [
43-
'debug' => $this->isDebugJavaScript(),
68+
'allowCookies' => $this->isUserAllowSaveCookies(),
4469
'apiKey' => (string) $this->getApiKey(),
70+
'debug' => $this->isDebugJavaScript(),
4571
'orderId' => \ltrim($order->getIncrementId(), '#'),
4672
'products' => \array_map(
47-
function ($item) {
73+
function ($item){
74+
$product = $this->productRepository->get($item->getSku());
4875
return [
49-
'id' => (string) $item->getSku(),
76+
'id' => (string) $product->getData($this->helper->getAttributeCode()),
5077
'quantity' => (int) $item->getQtyOrdered()
5178
];
5279
},
@@ -80,4 +107,4 @@ protected function getAllVisibleItems($order)
80107
}
81108
return $items;
82109
}
83-
}
110+
}

src/Block/Widget/Flow.php renamed to Block/Widget/Flow.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,28 @@ class Flow extends \Itonomy\Flowbox\Block\Base implements \Magento\Widget\Block\
1111
{
1212
protected $_template = "widget/flow.phtml";
1313

14-
/**
15-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
16-
*/
17-
private $productRepository;
18-
/**
19-
* @var \Magento\Framework\Api\SearchCriteriaBuilder
20-
*/
21-
private $searchCriteriaBuilder;
14+
private \Magento\Catalog\Api\ProductRepositoryInterface $productRepository;
15+
16+
private \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder;
2217

2318
/**
2419
* Flow constructor.
2520
* @param \Magento\Framework\View\Element\Template\Context $context
2621
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
2722
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
23+
* @param \Magento\Cookie\Helper\Cookie $cookie
2824
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
2925
* @param array $data
3026
*/
3127
public function __construct(
3228
\Magento\Framework\View\Element\Template\Context $context,
3329
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
3430
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
31+
\Magento\Cookie\Helper\Cookie $cookie,
3532
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
3633
array $data = []
3734
) {
38-
parent::__construct($context, $encryptor, $data);
35+
parent::__construct($context, $cookie, $encryptor, $data);
3936
$this->productRepository = $productRepository;
4037
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
4138
}
@@ -48,11 +45,11 @@ protected function prepareConfig(): void
4845
try {
4946
$flow = $this->getFlow();
5047
$config = [
48+
'allowCookies' => $this->isUserAllowSaveCookies(),
5149
'debug' => $this->isDebugJavaScript(),
5250
'flow' => $flow,
5351
'key' => $this->escapeHtml((string) $this->getData('key')),
5452
'lazyload' => (bool) $this->getData('lazyload'),
55-
'override_cookies' => $this->getData('override_cookies'),
5653
'locale' => (string) $this->pageConfig->getElementAttribute('html', 'lang')
5754
];
5855

Helper/Data.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Itonomy\Flowbox\Helper;
4+
5+
use Magento\Framework\App\Helper\AbstractHelper;
6+
use Magento\Framework\App\Config\ScopeConfigInterface;
7+
use Magento\Framework\Exception\NoSuchEntityException;
8+
use Magento\Store\Model\ScopeInterface;
9+
use Magento\Store\Model\StoreManagerInterface;
10+
11+
class Data extends AbstractHelper
12+
{
13+
/**
14+
* @var ScopeConfigInterface
15+
*/
16+
protected $scopeConfig;
17+
18+
/**
19+
* @var StoreManagerInterface
20+
*/
21+
protected $storeManager;
22+
23+
/**
24+
* @param ScopeConfigInterface $scopeConfig
25+
* @param StoreManagerInterface $storeManager
26+
*/
27+
public function __construct(
28+
ScopeConfigInterface $scopeConfig,
29+
StoreManagerInterface $storeManager
30+
) {
31+
$this->scopeConfig = $scopeConfig;
32+
$this->storeManager = $storeManager;
33+
}
34+
35+
/**
36+
* @return string
37+
* @throws NoSuchEntityException
38+
*/
39+
public function getAttributeCode(): string
40+
{
41+
return $this->scopeConfig->getValue(
42+
'itonomy_flowbox/general/checkout_identifier',
43+
ScopeInterface::SCOPE_STORE,
44+
$this->storeManager->getStore()->getId()
45+
);
46+
}
47+
}

Makefile

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@ ZIP := $(PKG).zip
44

55
module:
66
git checkout $(TAG)
7-
rm -rf ./pkg $(PKG)
8-
mkdir -p $(PKG)
9-
cp LICENSE.md README.md SECURITY.md $(PKG)/
10-
cp -R ./src/* $(PKG)/
11-
mkdir -p $(PKG)/docs
12-
cp -R ./docs/* $(PKG)/docs/
13-
sed 's/src\///g' composer.json > $(PKG)/composer.json
14-
zip -qr $(ZIP) $(PKG)
15-
rm -rf $(PKG)/*
16-
mv $(ZIP) $(PKG)/
17-
mv $(PKG) ./pkg
7+
zip -qr $(ZIP) .
8+
mkdir -p ./pkg/$(PKG)
9+
mv $(ZIP) ./pkg/$(PKG)/
1810

1911
.PHONY: clean
2012

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
4+
namespace Itonomy\Flowbox\Model\Config\Source;
5+
6+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection;
7+
use Magento\Framework\Data\OptionSourceInterface;
8+
9+
10+
class CheckoutIdentifier implements OptionSourceInterface
11+
{
12+
/**
13+
* @var Collection
14+
*/
15+
private $collection;
16+
17+
18+
/**
19+
* @param Collection $collection
20+
*/
21+
public function __construct(
22+
Collection $collection
23+
)
24+
{
25+
$this->collection = $collection;
26+
}
27+
28+
/**
29+
* @return array
30+
*/
31+
public function getUniqueAttributes(): array
32+
{
33+
$collection = $this->collection;
34+
35+
$collection->addFieldToFilter(
36+
'entity_type_id',
37+
['eq' => '4']
38+
);
39+
$collection->addFieldToFilter(
40+
'is_unique',
41+
['eq' => '1']
42+
);
43+
return $collection->toArray();
44+
}
45+
46+
/**
47+
* @return array
48+
*/
49+
public function toOptionArray(): array
50+
{
51+
$items = $this->getUniqueAttributes();
52+
$options = [];
53+
54+
if (array_key_exists('items', $items)) {
55+
foreach ($items['items'] as $item) {
56+
$options[] = ['value' => $item['attribute_code'],
57+
'label' => $item['frontend_label']
58+
];
59+
}
60+
}
61+
return $options;
62+
}
63+
}

Plugin/Elasticsearch.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Itonomy\Flowbox\Plugin;
4+
5+
class Elasticsearch
6+
{
7+
/**
8+
* @var \Magento\Framework\Search\Request\Config
9+
*/
10+
private $config;
11+
12+
/**
13+
* Elasticsearch constructor.
14+
* @param \Magento\Framework\Search\Request\Config $config
15+
*/
16+
public function __construct(\Magento\Framework\Search\Request\Config $config)
17+
{
18+
$this->config = $config;
19+
}
20+
21+
/**
22+
* @param \Magento\Elasticsearch7\Model\Client\Elasticsearch $subject
23+
* @param array $fields
24+
* @param string $index
25+
* @param string $entityType
26+
* @return array
27+
*/
28+
public function beforeAddFieldsMapping(
29+
\Magento\Elasticsearch7\Model\Client\Elasticsearch $subject,
30+
array $fields,
31+
string $index,
32+
string $entityType
33+
) : array {
34+
$mappings = $this->config->get();
35+
36+
foreach ($mappings as $config) {
37+
foreach($config['aggregations'] as $aggregation) {
38+
if (\array_key_exists('field', $aggregation)) {
39+
$field = $aggregation['field'];
40+
if (\array_key_exists($field, $fields) &&
41+
$fields[$field]['type'] === 'text'
42+
) {
43+
$fields[$field]['type'] = 'keyword';
44+
}
45+
if (\array_key_exists($field . '_value', $fields) &&
46+
$fields[$field . '_value']['type'] === 'text'
47+
) {
48+
$fields[$field]['type'] = 'keyword';
49+
}
50+
}
51+
}
52+
}
53+
54+
return [$fields, $index, $entityType];
55+
}
56+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Flowbox integration for Magento2
44

55
Facts
66
-----
7-
- version: 1.4.2
7+
- version: 1.4.6
88
- extension key: Itonomy_Flowbox
99

1010
Description

0 commit comments

Comments
 (0)