Skip to content

Commit f15ee81

Browse files
authored
Feature/product api v2 for release 2.1.0 (#20)
* Add event to push updated DataLayer to Ometria on Configurable product page simple variant selection. * Add configuration for preferred image functionality logic. * Implement preferred product image logic for front-end dataLayer. * Implement preferred product image logic for Product API. * Add Ometria API push for configurable products associated with product updates, to ensure preferred image data is maintained. * Fix addAttributeToFilter parameter type issue. * Mitigate issue no salable variant products causing error. * Align add to cart product ID for configurables with the PDP selection ID. * Prevent infinite loop when "Use Configurable Image" configuration is enabled. * Fix Product API bug where the last product is duplicated when requesting multiple IDs with listings=true. * Added Ometria specific log file and download functionality. Improved logging coverage. * M2-1 Added "count" parameter to retrieve count of entities from Products API. * M2-1 Added "count" parameter to retrieve count of entities from Orders API. * M2-1 Added "count" parameter to retrieve count of entities from Customers API. * M2-1 Added "count" parameter to retrieve count of entities from Attribute Types API. * Refactor Product API collection/array handling. * M2-1 Added "count" parameter to retrieve count of entities from Category API. * Clarify function parameters. * Refactor Ometria custom logger to adhere to new configuration to enable/disable logging. * WIP Product API v2 to improve performance. * Add order by product ID and rearrange the ordering of properties on Products API V1 to aid comparison of result with Product API V2. * Simplified preferred product image logic. * Revert "Refactor Ometria custom logger to adhere to new configuration to enable/disable logging." This reverts commit 0672f82. * Remove logging functionality. * Remove logging functionality. * Remove default page size when count parameter is set. * Amend default stock qty value to align with V1 product API. * Taking explicit page_size request param in to account when calculating product v2 api count.. * Refactor authentication to remove static functions and $_REQUEST global use which prevent testing. * Added integration test for Products API. * Add missing filter by entity IDs. * Add tax value and price including tax to Product API response. * Update integration test.
1 parent 238aec5 commit f15ee81

File tree

38 files changed

+2615
-847
lines changed

38 files changed

+2615
-847
lines changed

app/code/Ometria/AbandonedCarts/Controller/Cartlink/Index.php

100644100755
Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
namespace Ometria\AbandonedCarts\Controller\Cartlink;
33

4-
use Psr\Log\LoggerInterface;
5-
64
class Index extends \Magento\Framework\App\Action\Action
75
{
86
const CART_LINK_QUOTE_INVALID = 'Cart link is incorrect or expired';
@@ -12,25 +10,21 @@ class Index extends \Magento\Framework\App\Action\Action
1210
protected $abandonedCartsHelperConfig;
1311
protected $controllerResultRedirectFactory;
1412
protected $salesModelQuote;
15-
protected $messageManager;
13+
protected $messageManager;
1614
protected $checkoutSession;
1715
protected $session;
1816
protected $cookieHelper;
1917

20-
/** @var LoggerInterface */
21-
protected $logger;
22-
2318
public function __construct(
2419
\Magento\Framework\App\Action\Context $context,
25-
\Magento\Customer\Model\Session $customerModelSession,
26-
\Magento\Checkout\Model\Session $checkoutSession,
20+
\Magento\Customer\Model\Session $customerModelSession,
21+
\Magento\Checkout\Model\Session $checkoutSession,
2722
\Ometria\AbandonedCarts\Helper\Config $abandonedCartsHelperConfig,
2823
\Magento\Quote\Model\Quote $salesModelQuote,
2924
\Magento\Checkout\Model\Cart $cart,
3025
\Magento\Framework\Session\SessionManagerInterface $session,
31-
\Magento\Customer\Model\Visitor $visitor,
32-
\Magento\Framework\Stdlib\CookieManagerInterface $cookieHelper,
33-
LoggerInterface $logger
26+
\Magento\Customer\Model\Visitor $visitor,
27+
\Magento\Framework\Stdlib\CookieManagerInterface $cookieHelper
3428
)
3529
{
3630
$this->visitor = $visitor;
@@ -43,23 +37,22 @@ public function __construct(
4337
$this->checkoutSession = $checkoutSession;
4438
$this->cart = $cart;
4539
$this->cookieHelper = $cookieHelper;
46-
$this->logger = $logger;
4740

4841
return parent::__construct($context);
4942
}
50-
43+
5144
public function execute()
5245
{
5346
$session = $this->customerModelSession;
5447
$helper = $this->abandonedCartsHelperConfig;
55-
48+
5649
if (!$helper->isDeeplinkEnabled())
5750
{
5851
return $this->resultFactory->create(
5952
\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT
6053
)->setUrl('/');
6154
}
62-
55+
6356
$token = $this->getRequest()->getParam('token');
6457
$id = $this->getRequest()->getParam('id');
6558

@@ -79,38 +72,27 @@ public function execute()
7972
if ($helper->shouldCheckDeeplinkgToken())
8073
{
8174
$computed_token = substr(md5($quote->getCreatedAt().$quote->getId()), 0, 12);
82-
if ($token!=$computed_token)
75+
if ($token!=$computed_token)
8376
{
84-
// Log any token mismatches
85-
$this->logger->warning(
86-
self::CART_LINK_TOKEN_INVALID,
87-
[
88-
'token' => $computed_token,
89-
'quote' => [
90-
'id' => $quote->getId(),
91-
'created_at' => $quote->getCreatedAt()
92-
]
93-
]);
94-
9577
$this->messageManager->addNotice(self::CART_LINK_TOKEN_INVALID);
9678
return $this->resultFactory->create(
9779
\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT
9880
)->setUrl('/');
9981
}
10082
}
10183

102-
$this->checkoutSession->setQuoteId($quote->getId());
84+
$this->checkoutSession->setQuoteId($quote->getId());
10385
$data = $this->session->getVisitorData();
10486
$data['quote_id'] = $quote->getId();
10587
$data['last_visit_at'] = $data['last_visit_at'] ?? (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
10688
$this->session->setVisitorData($data);
10789
$this->visitor->setData($data)->save();
108-
90+
10991
return $this->resultFactory->create(
11092
\Magento\Framework\Controller\ResultFactory::TYPE_PAGE
11193
);
112-
}
113-
else
94+
}
95+
else
11496
{
11597
return $this->resultFactory->create(
11698
\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT

app/code/Ometria/AbandonedCarts/etc/adminhtml/system.xml

100644100755
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
<config>
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
23
<system>
3-
<!--
4-
<tab id="ometria" translate="label" sortOrder="1000">
5-
<label>Ometria</label>
6-
</tab>
7-
-->
8-
<section id="ometria_abandonedcarts" translate="label" sortOrder="1015" showInDefault="1" showInWebsite="1" showInStore="1">
4+
<section id="ometria_abandonedcarts" translate="label" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
95
<label>Cart Abandonment</label>
106
<tab>ometria</tab>
117
<resource>Ometria_Core::config_ometria</resource>
12-
<group id="abandonedcarts" translate="label" type="text" sortOrder="1020" showInDefault="1" showInWebsite="0" showInStore="0">
8+
<group id="abandonedcarts" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
139
<label>Cart Deeplink Settings</label>
1410
<frontend_model>Ometria\AbandonedCarts\Block\System\Config\Form\Fieldset\Modules\Group</frontend_model>
15-
<field id="cartpath" translate="label" type="text" sortOrder="1030" showInDefault="1" showInWebsite="0" showInStore="0">
11+
<field id="cartpath" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
1612
<label>Checkout Cart Path</label>
1713
<!-- <default>/checkout/cart</default> -->
1814
</field>
19-
<field id="enabled" translate="label" type="select" sortOrder="1040" showInDefault="1" showInWebsite="0" showInStore="0">
15+
<field id="enabled" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
2016
<label>Deeplink enabled</label>
2117
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2218
</field>
23-
<field id="check_token" translate="label" type="select" sortOrder="1050" showInDefault="1" showInWebsite="0" showInStore="0">
19+
<field id="check_token" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
2420
<label>Check Deeplink Token</label>
2521
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2622
</field>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<?xml version="1.0"?>
2-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"><module name="Ometria_AbandonedCarts" setup_version="2.0.3"/></config>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"><module name="Ometria_AbandonedCarts" setup_version="2.1.0"/></config>
3+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Ometria\Api\Api\Data;
4+
5+
interface ProductInterface
6+
{
7+
const TYPE = "@type";
8+
const ID = "id";
9+
const SKU = "sku";
10+
const TITLE = "title";
11+
const PRICE = "price";
12+
const SPECIAL_PRICE = "special_price";
13+
const FINAL_PRICE = "final_price";
14+
const FINAL_PRICE_INCL_TAX = "final_price_incl_tax";
15+
const TAX_AMOUNT = "tax";
16+
const URL = "url";
17+
const IMAGE_URL = "image_url";
18+
const IS_VARIANT = "is_variant";
19+
const PARENT_ID = "parent_id";
20+
const IS_ACTIVE = "is_active";
21+
const IS_IN_STOCK = "is_in_stock";
22+
const QTY = "qty";
23+
const STORES = "stores";
24+
const ATTRIBUTES = "attributes";
25+
const RAW = "_raw";
26+
const STORE_LISTINGS = "store_listings";
27+
const STATUS = 'status';
28+
const VISIBILITY = 'visibility';
29+
const STORE_ID = 'store_id';
30+
const STORE_CURRENCY = 'store_currency';
31+
}
Lines changed: 73 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,94 @@
11
<?php
22
namespace Ometria\Api\Controller\V1\Attribute;
3+
4+
use Magento\Framework\App\Action\Context;
5+
use Magento\Framework\Controller\Result\JsonFactory;
6+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
7+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as AttributeCollection;
8+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
39
use Ometria\Api\Helper\Format\V1\Attribute\Types as Helper;
4-
use \Ometria\Api\Controller\V1\Base;
10+
use Ometria\Api\Controller\V1\Base;
11+
512
class Types extends Base
613
{
714
protected $resultJsonFactory;
8-
protected $attributes;
9-
10-
public function __construct(
11-
\Magento\Framework\App\Action\Context $context,
12-
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
13-
\Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection $attributes
14-
) {
15-
parent::__construct($context);
16-
$this->resultJsonFactory = $resultJsonFactory;
17-
$this->attributes = $attributes;
18-
}
19-
20-
protected function serializeAttribute($attribute)
15+
protected $attributeCollectionFactory;
16+
17+
public function __construct(
18+
Context $context,
19+
JsonFactory $resultJsonFactory,
20+
AttributeCollectionFactory $attributeCollectionFactory
21+
) {
22+
parent::__construct($context);
23+
$this->resultJsonFactory = $resultJsonFactory;
24+
$this->attributeCollectionFactory = $attributeCollectionFactory;
25+
}
26+
27+
public function execute()
28+
{
29+
$collection = $this->attributeCollectionFactory->create();
30+
31+
if ($this->_request->getParam('count') != null) {
32+
$data = $this->getCountData($collection);
33+
} else {
34+
$data = $this->getItemsData($collection);
35+
}
36+
37+
return $this->resultJsonFactory->create()->setData($data);
38+
}
39+
40+
/**
41+
* @param $collection
42+
* @return array
43+
*/
44+
private function getCountData($collection)
45+
{
46+
return [
47+
'count' => $collection->count()
48+
];
49+
}
50+
51+
/**
52+
* @param $collection
53+
* @return array
54+
*/
55+
public function getItemsData($collection)
56+
{
57+
$data = [];
58+
59+
/** @var ProductAttributeInterface $attribute */
60+
foreach ($collection as $attribute) {
61+
$data[] = $this->serializeAttribute($attribute);
62+
}
63+
64+
return $data;
65+
}
66+
67+
/**
68+
* @param $attribute
69+
* @return null[]
70+
*/
71+
private function serializeAttribute($attribute)
2172
{
2273
$item = Helper::getBlankArray();
2374
$item['id'] = $attribute->getId();
2475
$item['title'] = $attribute->getFrontendLabel();
2576
$item['attribute_code'] = $attribute->getAttributeCode();
26-
switch($attribute->getData('frontend_input'))
27-
{
77+
78+
switch ($attribute->getData('frontend_input')) {
2879
case 'multiselect':
2980
$item['attribute_type'] = 'OPTION_LIST';
3081
break;
3182
case 'select':
3283
$item['attribute_type'] = 'OPTION';
33-
break;
34-
case 'boolean';
84+
break;
85+
case 'boolean':
3586
$item['attribute_type'] = 'OPTION';
36-
break;
87+
break;
3788
default:
3889
$item['attribute_type'] = 'FREETEXT';
3990
}
4091

41-
return $item;
42-
}
43-
44-
public function execute()
45-
{
46-
$data = [];
47-
// $tmp = [];
48-
foreach($this->attributes as $attribute)
49-
{
50-
// $tmp[$attribute->getFrontendInput()] = 0;
51-
$data[] = $this->serializeAttribute($attribute);
52-
}
53-
54-
$result = $this->resultJsonFactory->create();
55-
return $result->setData($data);
56-
57-
}
58-
}
92+
return $item;
93+
}
94+
}

app/code/Ometria/Api/Controller/V1/Base.php

100644100755
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?php
22
namespace Ometria\Api\Controller\V1;
3-
abstract class Base extends \Magento\Framework\App\Action\Action
3+
4+
use Magento\Framework\App\Action\Action;
5+
use Magento\Framework\App\RequestInterface;
6+
7+
abstract class Base extends Action
48
{
5-
public function dispatch(
6-
\Magento\Framework\App\RequestInterface $request)
7-
{
8-
return parent::dispatch($request);
9-
}
10-
}
9+
}

0 commit comments

Comments
 (0)