Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddPaymentWeeeItem.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
21  private $weeeData;
22 
26  private $storeManager;
27 
32  public function __construct(
33  Data $weeeData,
34  StoreManagerInterface $storeManager
35  ) {
36  $this->weeeData = $weeeData;
37  $this->storeManager = $storeManager;
38  }
39 
46  public function execute(Observer $observer)
47  {
48  if ($this->shouldBeAddedAsCustomItem() === false) {
49  return;
50  }
51 
53  $cart = $observer->getEvent()->getCart();
54  $salesEntity = $cart->getSalesModel();
55 
56  $totalWeee = 0;
57  foreach ($salesEntity->getAllItems() as $item) {
58  $originalItem = $item->getOriginalItem();
59  if (!$originalItem->getParentItem()) {
60  $totalWeee += $this->weeeData->getBaseWeeeTaxAppliedRowAmount($originalItem);
61  }
62  }
63 
64  if ($totalWeee > 0.0001) {
65  $cart->addCustomItem(__('FPT'), 1, $totalWeee);
66  }
67  }
68 
74  private function shouldBeAddedAsCustomItem()
75  {
76  $storeId = $this->storeManager->getStore()->getId();
77 
78  return $this->weeeData->isEnabled($storeId) && $this->weeeData->includeInSubtotal($storeId) === false;
79  }
80 }
__construct(Data $weeeData, StoreManagerInterface $storeManager)
$storeManager
__()
Definition: __.php:13