Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Processor Class Reference

Public Member Functions

 __construct (ItemFactory $quoteItemFactory, StoreManagerInterface $storeManager, State $appState)
 
 init (Product $product, DataObject $request)
 
 prepare (Item $item, DataObject $request, Product $candidate)
 
 merge (Item $source, Item $target)
 

Protected Member Functions

 setItemStoreId (Item $item)
 

Protected Attributes

 $quoteItemFactory
 
 $storeManager
 
 $appState
 

Detailed Description

Class Processor

Definition at line 21 of file Processor.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ItemFactory  $quoteItemFactory,
StoreManagerInterface  $storeManager,
State  $appState 
)
Parameters
ItemFactory$quoteItemFactory
StoreManagerInterface$storeManager
State$appState

Definition at line 43 of file Processor.php.

47  {
48  $this->quoteItemFactory = $quoteItemFactory;
49  $this->storeManager = $storeManager;
50  $this->appState = $appState;
51  }

Member Function Documentation

◆ init()

init ( Product  $product,
DataObject  $request 
)

Initialize quote item object

Parameters
DataObject$request
Product$product
Returns
Item

We can't modify existing child items

Definition at line 61 of file Processor.php.

61  : Item
62  {
63  $item = $this->quoteItemFactory->create();
64 
65  $this->setItemStoreId($item);
66 
70  if ($item->getId() && $product->getParentProductId()) {
71  return $item;
72  }
73 
74  if ($request->getResetCount() && !$product->getStickWithinParent() && $item->getId() === $request->getId()) {
75  $item->setData(CartItemInterface::KEY_QTY, 0);
76  }
77 
78  return $item;
79  }

◆ merge()

merge ( Item  $source,
Item  $target 
)

Merge two quote items.

Parameters
Item$source
Item$target
Returns
Item

@SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 115 of file Processor.php.

115  : Item
116  {
117  return $target;
118  }
$target
Definition: skip.phtml:8

◆ prepare()

prepare ( Item  $item,
DataObject  $request,
Product  $candidate 
)

Set qty and custom price for quote item

Parameters
Item$item
DataObject$request
Product$candidate
Returns
void

We specify qty after we know about parent (for stock)

Definition at line 89 of file Processor.php.

89  : void
90  {
94  if ($request->getResetCount() && !$candidate->getStickWithinParent() && $item->getId() == $request->getId()) {
95  $item->setData(CartItemInterface::KEY_QTY, 0);
96  }
97  $item->addQty($candidate->getCartQty());
98 
99  $customPrice = $request->getCustomPrice();
100  if (!empty($customPrice)) {
101  $item->setCustomPrice($customPrice);
102  $item->setOriginalCustomPrice($customPrice);
103  }
104  }

◆ setItemStoreId()

setItemStoreId ( Item  $item)
protected

Set store_id value to quote item

Parameters
Item$item
Returns
void

Definition at line 126 of file Processor.php.

126  : void
127  {
128  if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
129  $storeId = $this->storeManager->getStore($this->storeManager->getStore()->getId())
130  ->getId();
131  $item->setStoreId($storeId);
132  } else {
133  $item->setStoreId($this->storeManager->getStore()->getId());
134  }
135  }

Field Documentation

◆ $appState

$appState
protected

Definition at line 36 of file Processor.php.

◆ $quoteItemFactory

$quoteItemFactory
protected

Definition at line 26 of file Processor.php.

◆ $storeManager

$storeManager
protected

Definition at line 31 of file Processor.php.


The documentation for this class was generated from the following file: