Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Weee Class Reference
Inheritance diagram for Weee:
AbstractTotal CollectorInterface ReaderInterface WeeeTax

Public Member Functions

 __construct (\Magento\Weee\Helper\Data $weeeData, PriceCurrencyInterface $priceCurrency)
 
 collect (\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 
 fetch (\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
 
 processConfigArray ($config, $store)
 
 getLabel ()
 
- Public Member Functions inherited from AbstractTotal
 setCode ($code)
 
 getCode ()
 
 getLabel ()
 
 collect (\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
 
 fetch (\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
 
 _setTotal (\Magento\Quote\Model\Quote\Address\Total $total)
 
 getItemRowTotal (\Magento\Quote\Model\Quote\Item\AbstractItem $item)
 
 getItemBaseRowTotal (\Magento\Quote\Model\Quote\Item\AbstractItem $item)
 
 getIsItemRowTotalCompoundable (\Magento\Quote\Model\Quote\Item\AbstractItem $item)
 
 processConfigArray ($config, $store)
 

Data Fields

const ITEM_CODE_WEEE_PREFIX = 'weee'
 
const ITEM_TYPE = 'weee'
 

Protected Member Functions

 process (\Magento\Quote\Model\Quote\Address $address, \Magento\Quote\Model\Quote\Address\Total $total, $item)
 
 processTotalAmount ( $total, $rowValueExclTax, $baseRowValueExclTax, $rowValueInclTax, $baseRowValueInclTax)
 
 getNextIncrement ()
 
 recalculateParent (\Magento\Quote\Model\Quote\Item\AbstractItem $item)
 
 resetItemData ($item)
 
- Protected Member Functions inherited from AbstractTotal
 _setAddress (\Magento\Quote\Model\Quote\Address $address)
 
 _getAddress ()
 
 _getTotal ()
 
 _setAmount ($amount)
 
 _setBaseAmount ($baseAmount)
 
 _addAmount ($amount)
 
 _addBaseAmount ($baseAmount)
 
 _getAddressItems (\Magento\Quote\Model\Quote\Address $address)
 

Protected Attributes

 $weeeData
 
 $_store
 
 $counter = 0
 
 $weeeCodeToItemMap
 
 $weeeTotalExclTax
 
 $weeeBaseTotalExclTax
 
 $priceCurrency
 
- Protected Attributes inherited from AbstractTotal
 $_code
 
 $_address = null
 
 $_canAddAmountToAddress = true
 
 $_canSetAddressAmount = true
 
 $_itemRowTotalKey = null
 
 $total
 

Detailed Description

Definition at line 14 of file Weee.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Weee\Helper\Data  $weeeData,
PriceCurrencyInterface  $priceCurrency 
)
Parameters
\Magento\Weee\Helper\Data$weeeData
PriceCurrencyInterface$priceCurrency

Definition at line 72 of file Weee.php.

75  {
76  $this->priceCurrency = $priceCurrency;
77  $this->weeeData = $weeeData;
78  $this->setCode('weee');
79  $this->weeeCodeToItemMap = [];
80  }

Member Function Documentation

◆ collect()

Collect Weee amounts for the quote / order

Parameters
\Magento\Quote\Model\Quote$quote
\Magento\Quote\Api\Data\ShippingAssignmentInterface$shippingAssignment
\Magento\Quote\Model\Quote\Address\Total$total
Returns
$this

Definition at line 90 of file Weee.php.

94  {
95  AbstractTotal::collect($quote, $shippingAssignment, $total);
96  $this->_store = $quote->getStore();
97  if (!$this->weeeData->isEnabled($this->_store)) {
98  return $this;
99  }
100 
101  $address = $shippingAssignment->getShipping()->getAddress();
102  $items = $shippingAssignment->getItems();
103  if (!count($items)) {
104  return $this;
105  }
106 
107  $this->weeeTotalExclTax = 0;
108  $this->weeeBaseTotalExclTax = 0;
109  foreach ($items as $item) {
110  if ($item->getParentItem()) {
111  continue;
112  }
113  $this->resetItemData($item);
114  if ($item->getHasChildren() && $item->isChildrenCalculated()) {
115  foreach ($item->getChildren() as $child) {
116  $this->resetItemData($child);
117  $this->process($address, $total, $child);
118  }
119  $this->recalculateParent($item);
120  } else {
121  $this->process($address, $total, $item);
122  }
123  }
124  $total->setWeeeCodeToItemMap($this->weeeCodeToItemMap);
125  $total->setWeeeTotalExclTax($this->weeeTotalExclTax);
126  $total->setWeeeBaseTotalExclTax($this->weeeBaseTotalExclTax);
127  return $this;
128  }
collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
$quote
recalculateParent(\Magento\Quote\Model\Quote\Item\AbstractItem $item)
Definition: Weee.php:300
$address
Definition: customer.php:38
process(\Magento\Quote\Model\Quote\Address $address, \Magento\Quote\Model\Quote\Address\Total $total, $item)
Definition: Weee.php:140
$items

◆ fetch()

Parameters
\Magento\Quote\Model\Quote$quote
\Magento\Quote\Model\Quote\Address\Total$total
Returns
array|null @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 340 of file Weee.php.

341  {
342  return null;
343  }

◆ getLabel()

getLabel ( )

No aggregated label for fixed product tax

TODO: fix

Returns
string

Definition at line 366 of file Weee.php.

367  {
368  return '';
369  }

◆ getNextIncrement()

getNextIncrement ( )
protected

Increment and return counter. This function is intended to be used to generate temporary id for an item.

Returns
int

Definition at line 287 of file Weee.php.

288  {
289  return ++$this->counter;
290  }

◆ process()

process ( \Magento\Quote\Model\Quote\Address  $address,
\Magento\Quote\Model\Quote\Address\Total  $total,
  $item 
)
protected

Calculate item fixed tax and prepare information for discount and regular taxation

Parameters
\Magento\Quote\Model\Quote\Address$address
\Magento\Quote\Model\Quote\Address\Total$total
\Magento\Quote\Model\Quote\Item\AbstractItem$item
Returns
void|$this @SuppressWarnings(PHPMD.ExcessiveMethodLength) @SuppressWarnings(PHPMD.UnusedLocalVariable)

Definition at line 140 of file Weee.php.

144  {
145  $attributes = $this->weeeData->getProductWeeeAttributes(
146  $item->getProduct(),
147  $address,
148  $address->getQuote()->getBillingAddress(),
149  $this->_store->getWebsiteId()
150  );
151 
152  $productTaxes = [];
153 
154  $totalValueInclTax = 0;
155  $baseTotalValueInclTax = 0;
156  $totalRowValueInclTax = 0;
157  $baseTotalRowValueInclTax = 0;
158 
159  $totalValueExclTax = 0;
160  $baseTotalValueExclTax = 0;
161  $totalRowValueExclTax = 0;
162  $baseTotalRowValueExclTax = 0;
163 
164  $associatedTaxables = $item->getAssociatedTaxables();
165  if (!$associatedTaxables) {
166  $associatedTaxables = [];
167  } else {
168  // remove existing weee associated taxables
169  foreach ($associatedTaxables as $iTaxable => $taxable) {
170  if ($taxable[CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_TYPE] == self::ITEM_TYPE) {
171  unset($associatedTaxables[$iTaxable]);
172  }
173  }
174  }
175 
176  foreach ($attributes as $key => $attribute) {
177  $title = $attribute->getName();
178 
179  $baseValueExclTax = $baseValueInclTax = $attribute->getAmount();
180  $valueExclTax = $valueInclTax = $this->priceCurrency->round(
181  $this->priceCurrency->convert($baseValueExclTax, $this->_store)
182  );
183 
184  $rowValueInclTax = $rowValueExclTax = $this->priceCurrency->round($valueInclTax * $item->getTotalQty());
185  $baseRowValueInclTax = $this->priceCurrency->round($baseValueInclTax * $item->getTotalQty());
186  $baseRowValueExclTax = $baseRowValueInclTax;
187 
188  $totalValueInclTax += $valueInclTax;
189  $baseTotalValueInclTax += $baseValueInclTax;
190  $totalRowValueInclTax += $rowValueInclTax;
191  $baseTotalRowValueInclTax += $baseRowValueInclTax;
192 
193  $totalValueExclTax += $valueExclTax;
194  $baseTotalValueExclTax += $baseValueExclTax;
195  $totalRowValueExclTax += $rowValueExclTax;
196  $baseTotalRowValueExclTax += $baseRowValueExclTax;
197 
198  $productTaxes[] = [
199  'title' => $title,
200  'base_amount' => $baseValueExclTax,
201  'amount' => $valueExclTax,
202  'row_amount' => $rowValueExclTax,
203  'base_row_amount' => $baseRowValueExclTax,
204  'base_amount_incl_tax' => $baseValueInclTax,
205  'amount_incl_tax' => $valueInclTax,
206  'row_amount_incl_tax' => $rowValueInclTax,
207  'base_row_amount_incl_tax' => $baseRowValueInclTax,
208  ];
209 
210  if ($this->weeeData->isTaxable($this->_store)) {
211  $weeeItemCode = self::ITEM_CODE_WEEE_PREFIX . $this->getNextIncrement();
212  $weeeItemCode .= '-' . $title;
213 
214  $associatedTaxables[] = [
220  CommonTaxCollector::KEY_ASSOCIATED_TAXABLE_TAX_CLASS_ID => $item->getProduct()->getTaxClassId(),
221  ];
222  $this->weeeCodeToItemMap[$weeeItemCode] = $item;
223  }
224  }
225  $item->setAssociatedTaxables($associatedTaxables);
226 
227  $item->setWeeeTaxAppliedAmount($totalValueExclTax)
228  ->setBaseWeeeTaxAppliedAmount($baseTotalValueExclTax)
229  ->setWeeeTaxAppliedRowAmount($totalRowValueExclTax)
230  ->setBaseWeeeTaxAppliedRowAmnt($baseTotalRowValueExclTax);
231 
232  $item->setWeeeTaxAppliedAmountInclTax($totalValueInclTax)
233  ->setBaseWeeeTaxAppliedAmountInclTax($baseTotalValueInclTax)
234  ->setWeeeTaxAppliedRowAmountInclTax($totalRowValueInclTax)
235  ->setBaseWeeeTaxAppliedRowAmntInclTax($baseTotalRowValueInclTax);
236 
237  $this->processTotalAmount(
238  $total,
239  $totalRowValueExclTax,
240  $baseTotalRowValueExclTax,
241  $totalRowValueInclTax,
242  $baseTotalRowValueInclTax
243  );
244 
245  $this->weeeData->setApplied($item, array_merge($this->weeeData->getApplied($item), $productTaxes));
246  }
$title
Definition: default.phtml:14
$address
Definition: customer.php:38
processTotalAmount( $total, $rowValueExclTax, $baseRowValueExclTax, $rowValueInclTax, $baseRowValueInclTax)
Definition: Weee.php:258
$attributes
Definition: matrix.phtml:13

◆ processConfigArray()

processConfigArray (   $config,
  $store 
)

Process model configuration array. This method can be used for changing totals collect sort order

Parameters
array$config
Store$store
Returns
array

@SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 355 of file Weee.php.

356  {
357  return $config;
358  }
$config
Definition: fraud_order.php:17

◆ processTotalAmount()

processTotalAmount (   $total,
  $rowValueExclTax,
  $baseRowValueExclTax,
  $rowValueInclTax,
  $baseRowValueInclTax 
)
protected

Process row amount based on FPT total amount configuration setting

Parameters
\Magento\Quote\Model\Quote\Address\Total$total
float$rowValueExclTax
float$baseRowValueExclTax
float$rowValueInclTax
float$baseRowValueInclTax
Returns
$this

Definition at line 258 of file Weee.php.

264  {
265  if (!$this->weeeData->isTaxable($this->_store)) {
266  //Accumulate the values. Will be used later in the 'weee tax' collector
267  $this->weeeTotalExclTax += $this->priceCurrency->round($rowValueExclTax);
268  $this->weeeBaseTotalExclTax += $this->priceCurrency->round($baseRowValueExclTax);
269  }
270 
271  //This value is used to calculate shipping cost; it will be overridden by tax collector
272  $total->setSubtotalInclTax(
273  $total->getSubtotalInclTax() + $this->priceCurrency->round($rowValueInclTax)
274  );
275  $total->setBaseSubtotalInclTax(
276  $total->getBaseSubtotalInclTax() + $this->priceCurrency->round($baseRowValueInclTax)
277  );
278  return $this;
279  }

◆ recalculateParent()

recalculateParent ( \Magento\Quote\Model\Quote\Item\AbstractItem  $item)
protected

Recalculate parent item amounts based on children results

Parameters
\Magento\Quote\Model\Quote\Item\AbstractItem$item
Returns
void

@SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 300 of file Weee.php.

301  {
302  $associatedTaxables = [];
303  foreach ($item->getChildren() as $child) {
304  $associatedTaxables = array_merge($associatedTaxables, $child->getAssociatedTaxables());
305  }
306  $item->setAssociatedTaxables($associatedTaxables);
307  }

◆ resetItemData()

resetItemData (   $item)
protected

Reset information about Tax and Wee on FPT for shopping cart item

Parameters
\Magento\Quote\Model\Quote\Item\AbstractItem$item
Returns
void

Definition at line 315 of file Weee.php.

316  {
317  $this->weeeData->setApplied($item, []);
318 
319  $item->setAssociatedTaxables([]);
320 
321  $item->setBaseWeeeTaxDisposition(0);
322  $item->setWeeeTaxDisposition(0);
323 
324  $item->setBaseWeeeTaxRowDisposition(0);
325  $item->setWeeeTaxRowDisposition(0);
326 
327  $item->setBaseWeeeTaxAppliedAmount(0);
328  $item->setBaseWeeeTaxAppliedRowAmnt(0);
329 
330  $item->setWeeeTaxAppliedAmount(0);
331  $item->setWeeeTaxAppliedRowAmount(0);
332  }

Field Documentation

◆ $_store

$_store
protected

Definition at line 33 of file Weee.php.

◆ $counter

$counter = 0
protected

Definition at line 40 of file Weee.php.

◆ $priceCurrency

$priceCurrency
protected

Definition at line 66 of file Weee.php.

◆ $weeeBaseTotalExclTax

$weeeBaseTotalExclTax
protected

Definition at line 61 of file Weee.php.

◆ $weeeCodeToItemMap

$weeeCodeToItemMap
protected

Definition at line 47 of file Weee.php.

◆ $weeeData

$weeeData
protected

Definition at line 28 of file Weee.php.

◆ $weeeTotalExclTax

$weeeTotalExclTax
protected

Definition at line 54 of file Weee.php.

◆ ITEM_CODE_WEEE_PREFIX

const ITEM_CODE_WEEE_PREFIX = 'weee'

Constant for weee item code prefix

Definition at line 19 of file Weee.php.

◆ ITEM_TYPE

const ITEM_TYPE = 'weee'

Constant for weee item type

Definition at line 23 of file Weee.php.


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