1
1
<?php
2
2
/**
3
+ *
3
4
* Copyright © Magento, Inc. All rights reserved.
4
5
* See COPYING.txt for license details.
5
6
*/
6
7
7
8
namespace Magento \Quote \Model \Quote \Item ;
8
9
9
- use Magento \Catalog \ Api \ ProductRepositoryInterface ;
10
+ use Magento \Framework \ App \ ObjectManager ;
10
11
use Magento \Framework \Exception \CouldNotSaveException ;
11
- use Magento \Framework \Exception \InputException ;
12
12
use Magento \Framework \Exception \NoSuchEntityException ;
13
- use Magento \Quote \Api \CartItemRepositoryInterface ;
14
- use Magento \Quote \Api \CartRepositoryInterface ;
15
- use Magento \Quote \Api \Data \CartItemInterfaceFactory ;
16
13
17
- /**
18
- * Repository for quote item.
19
- */
20
- class Repository implements CartItemRepositoryInterface
14
+ class Repository implements \Magento \Quote \Api \CartItemRepositoryInterface
21
15
{
22
16
/**
23
17
* Quote repository.
24
18
*
25
- * @var CartRepositoryInterface
19
+ * @var \Magento\Quote\Api\ CartRepositoryInterface
26
20
*/
27
21
protected $ quoteRepository ;
28
22
29
23
/**
30
24
* Product repository.
31
25
*
32
- * @var ProductRepositoryInterface
26
+ * @var \Magento\Catalog\Api\ ProductRepositoryInterface
33
27
*/
34
28
protected $ productRepository ;
35
29
36
30
/**
37
- * @var CartItemInterfaceFactory
31
+ * @var \Magento\Quote\Api\Data\ CartItemInterfaceFactory
38
32
*/
39
33
protected $ itemDataFactory ;
40
34
@@ -49,28 +43,25 @@ class Repository implements CartItemRepositoryInterface
49
43
private $ cartItemOptionsProcessor ;
50
44
51
45
/**
52
- * @param CartRepositoryInterface $quoteRepository
53
- * @param ProductRepositoryInterface $productRepository
54
- * @param CartItemInterfaceFactory $itemDataFactory
55
- * @param CartItemOptionsProcessor $cartItemOptionsProcessor
46
+ * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
47
+ * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
48
+ * @param \Magento\Quote\Api\Data\CartItemInterfaceFactory $itemDataFactory
56
49
* @param CartItemProcessorInterface[] $cartItemProcessors
57
50
*/
58
51
public function __construct (
59
- CartRepositoryInterface $ quoteRepository ,
60
- ProductRepositoryInterface $ productRepository ,
61
- CartItemInterfaceFactory $ itemDataFactory ,
62
- CartItemOptionsProcessor $ cartItemOptionsProcessor ,
52
+ \Magento \Quote \Api \CartRepositoryInterface $ quoteRepository ,
53
+ \Magento \Catalog \Api \ProductRepositoryInterface $ productRepository ,
54
+ \Magento \Quote \Api \Data \CartItemInterfaceFactory $ itemDataFactory ,
63
55
array $ cartItemProcessors = []
64
56
) {
65
57
$ this ->quoteRepository = $ quoteRepository ;
66
58
$ this ->productRepository = $ productRepository ;
67
59
$ this ->itemDataFactory = $ itemDataFactory ;
68
- $ this ->cartItemOptionsProcessor = $ cartItemOptionsProcessor ;
69
60
$ this ->cartItemProcessors = $ cartItemProcessors ;
70
61
}
71
62
72
63
/**
73
- * @inheritdoc
64
+ * { @inheritdoc}
74
65
*/
75
66
public function getList ($ cartId )
76
67
{
@@ -80,26 +71,21 @@ public function getList($cartId)
80
71
81
72
/** @var \Magento\Quote\Model\Quote\Item $item */
82
73
foreach ($ quote ->getAllVisibleItems () as $ item ) {
83
- $ item = $ this ->cartItemOptionsProcessor ->addProductOptions ($ item ->getProductType (), $ item );
84
- $ output [] = $ this ->cartItemOptionsProcessor ->applyCustomOptions ($ item );
74
+ $ item = $ this ->getCartItemOptionsProcessor () ->addProductOptions ($ item ->getProductType (), $ item );
75
+ $ output [] = $ this ->getCartItemOptionsProcessor () ->applyCustomOptions ($ item );
85
76
}
86
77
return $ output ;
87
78
}
88
79
89
80
/**
90
- * @inheritdoc
81
+ * { @inheritdoc}
91
82
*/
92
83
public function save (\Magento \Quote \Api \Data \CartItemInterface $ cartItem )
93
84
{
94
85
/** @var \Magento\Quote\Model\Quote $quote */
95
86
$ cartId = $ cartItem ->getQuoteId ();
96
- if (!$ cartId ) {
97
- throw new InputException (
98
- __ ('"%fieldName" is required. Enter and try again. ' , ['fieldName ' => 'cartId ' ])
99
- );
100
- }
101
-
102
87
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
88
+
103
89
$ quoteItems = $ quote ->getItems ();
104
90
$ quoteItems [] = $ cartItem ;
105
91
$ quote ->setItems ($ quoteItems );
@@ -109,7 +95,7 @@ public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem)
109
95
}
110
96
111
97
/**
112
- * @inheritdoc
98
+ * { @inheritdoc}
113
99
*/
114
100
public function deleteById ($ cartId , $ itemId )
115
101
{
@@ -130,4 +116,17 @@ public function deleteById($cartId, $itemId)
130
116
131
117
return true ;
132
118
}
119
+
120
+ /**
121
+ * @return CartItemOptionsProcessor
122
+ * @deprecated 100.1.0
123
+ */
124
+ private function getCartItemOptionsProcessor ()
125
+ {
126
+ if (!$ this ->cartItemOptionsProcessor instanceof CartItemOptionsProcessor) {
127
+ $ this ->cartItemOptionsProcessor = ObjectManager::getInstance ()->get (CartItemOptionsProcessor::class);
128
+ }
129
+
130
+ return $ this ->cartItemOptionsProcessor ;
131
+ }
133
132
}
0 commit comments