Skip to content

Commit 4ddbfc2

Browse files
committed
Remove Zend_Json usage from the minicart.phtml template
1 parent 122997c commit 4ddbfc2

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class Sidebar extends AbstractCart
2727
*/
2828
protected $imageHelper;
2929

30+
/**
31+
* @var \Magento\Framework\Serialize\SerializerInterface
32+
*/
33+
private $serializer;
34+
3035
/**
3136
* @param \Magento\Framework\View\Element\Template\Context $context
3237
* @param \Magento\Customer\Model\Session $customerSession
@@ -42,6 +47,7 @@ public function __construct(
4247
\Magento\Checkout\Model\Session $checkoutSession,
4348
\Magento\Catalog\Helper\Image $imageHelper,
4449
\Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface $jsLayoutDataProvider,
50+
\Magento\Framework\Serialize\SerializerInterface $serializer = null,
4551
array $data = []
4652
) {
4753
if (isset($data['jsLayout'])) {
@@ -53,6 +59,8 @@ public function __construct(
5359
parent::__construct($context, $customerSession, $checkoutSession, $data);
5460
$this->_isScopePrivate = false;
5561
$this->imageHelper = $imageHelper;
62+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
63+
->get(\Magento\Framework\Serialize\SerializerInterface::class);
5664
}
5765

5866
/**
@@ -74,6 +82,14 @@ public function getConfig()
7482
];
7583
}
7684

85+
/**
86+
* @return string
87+
*/
88+
public function getSerializedConfig()
89+
{
90+
return $this->serializer->serialize($this->getConfig());
91+
}
92+
7793
/**
7894
* @return string
7995
*/

app/code/Magento/Checkout/Test/Unit/Block/Cart/SidebarTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class SidebarTest extends \PHPUnit_Framework_TestCase
5353
*/
5454
protected $requestMock;
5555

56+
/**
57+
* @var \PHPUnit_Framework_MockObject_MockObject
58+
*/
59+
private $serializer;
60+
5661
protected function setUp()
5762
{
5863
$this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -94,12 +99,15 @@ protected function setUp()
9499
->method('getRequest')
95100
->will($this->returnValue($this->requestMock));
96101

102+
$this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class,[],[],'',false);
103+
97104
$this->model = $this->_objectManager->getObject(
98105
\Magento\Checkout\Block\Cart\Sidebar::class,
99106
[
100107
'context' => $contextMock,
101108
'imageHelper' => $this->imageHelper,
102-
'checkoutSession' => $this->checkoutSessionMock
109+
'checkoutSession' => $this->checkoutSessionMock,
110+
'serializer' => $this->serializer
103111
]
104112
);
105113
}

app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</div>
4444
<?php endif ?>
4545
<script>
46-
window.checkout = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getConfig()); ?>;
46+
window.checkout = <?php /* @escapeNotVerified */ echo $block->getSerializedConfig(); ?>;
4747
</script>
4848
<script type="text/x-magento-init">
4949
{

0 commit comments

Comments
 (0)