Skip to content

Commit 1fe484b

Browse files
ENGCOM-6514: Code refactor, updated Unit Test with JsonHexTag Serializer #26136
2 parents 7e97c78 + f8b9ade commit 1fe484b

File tree

2 files changed

+207
-81
lines changed

2 files changed

+207
-81
lines changed

app/code/Magento/Checkout/Block/Cart/Shipping.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,73 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Checkout\Block\Cart;
78

9+
use Magento\Checkout\Model\CompositeConfigProvider;
10+
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
11+
use Magento\Framework\Serialize\Serializer\Json;
12+
use Magento\Framework\Serialize\Serializer\JsonHexTag;
13+
use Magento\Framework\View\Element\Template\Context;
14+
use Magento\Customer\Model\Session as CustomerSession;
15+
use Magento\Checkout\Model\Session as CheckoutSession;
16+
use Magento\Framework\App\ObjectManager;
17+
818
/**
19+
* Cart Shipping Block
20+
*
921
* @api
1022
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1123
*/
1224
class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
1325
{
1426
/**
15-
* @var \Magento\Checkout\Model\CompositeConfigProvider
27+
* @var CompositeConfigProvider
1628
*/
1729
protected $configProvider;
1830

1931
/**
20-
* @var array|\Magento\Checkout\Block\Checkout\LayoutProcessorInterface[]
32+
* @var array|LayoutProcessorInterface[]
2133
*/
2234
protected $layoutProcessors;
2335

2436
/**
25-
* @var \Magento\Framework\Serialize\Serializer\Json
37+
* @var Json
2638
*/
2739
private $serializer;
2840

2941
/**
30-
* @param \Magento\Framework\View\Element\Template\Context $context
31-
* @param \Magento\Customer\Model\Session $customerSession
32-
* @param \Magento\Checkout\Model\Session $checkoutSession
33-
* @param \Magento\Checkout\Model\CompositeConfigProvider $configProvider
42+
* @var JsonHexTag
43+
*/
44+
private $jsonHexTagSerializer;
45+
46+
/**
47+
* @param Context $context
48+
* @param CustomerSession $customerSession
49+
* @param CheckoutSession $checkoutSession
50+
* @param CompositeConfigProvider $configProvider
3451
* @param array $layoutProcessors
3552
* @param array $data
36-
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
53+
* @param Json|null $serializer
54+
* @param JsonHexTag|null $jsonHexTagSerializer
3755
* @throws \RuntimeException
3856
*/
3957
public function __construct(
40-
\Magento\Framework\View\Element\Template\Context $context,
41-
\Magento\Customer\Model\Session $customerSession,
42-
\Magento\Checkout\Model\Session $checkoutSession,
43-
\Magento\Checkout\Model\CompositeConfigProvider $configProvider,
58+
Context $context,
59+
CustomerSession $customerSession,
60+
CheckoutSession $checkoutSession,
61+
CompositeConfigProvider $configProvider,
4462
array $layoutProcessors = [],
4563
array $data = [],
46-
\Magento\Framework\Serialize\Serializer\Json $serializer = null
64+
Json $serializer = null,
65+
JsonHexTag $jsonHexTagSerializer = null
4766
) {
4867
$this->configProvider = $configProvider;
4968
$this->layoutProcessors = $layoutProcessors;
5069
parent::__construct($context, $customerSession, $checkoutSession, $data);
5170
$this->_isScopePrivate = true;
52-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
53-
->get(\Magento\Framework\Serialize\Serializer\Json::class);
71+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
72+
$this->jsonHexTagSerializer = $jsonHexTagSerializer ?: ObjectManager::getInstance()->get(JsonHexTag::class);
5473
}
5574

5675
/**
@@ -75,7 +94,7 @@ public function getJsLayout()
7594
$this->jsLayout = $processor->process($this->jsLayout);
7695
}
7796

78-
return json_encode($this->jsLayout, JSON_HEX_TAG);
97+
return $this->jsonHexTagSerializer->serialize($this->jsLayout);
7998
}
8099

81100
/**
@@ -90,11 +109,13 @@ public function getBaseUrl()
90109
}
91110

92111
/**
112+
* Get Serialized Checkout Config
113+
*
93114
* @return bool|string
94115
* @since 100.2.0
95116
*/
96117
public function getSerializedCheckoutConfig()
97118
{
98-
return json_encode($this->getCheckoutConfig(), JSON_HEX_TAG);
119+
return $this->jsonHexTagSerializer->serialize($this->getCheckoutConfig());
99120
}
100121
}

0 commit comments

Comments
 (0)