Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TotalsConverter.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Quote\Api\Data\TotalSegmentInterfaceFactory;
10 
15 {
19  protected $factory;
20 
24  public function __construct(
25  TotalSegmentInterfaceFactory $factory
26  ) {
27  $this->factory = $factory;
28  }
29 
34  public function process($addressTotals)
35  {
36  $data = [];
38  foreach ($addressTotals as $addressTotal) {
39  $pureData = [
40  TotalSegmentInterface::CODE => $addressTotal->getCode(),
42  TotalSegmentInterface::VALUE => $addressTotal->getValue(),
43  TotalSegmentInterface::AREA => $addressTotal->getArea(),
44  ];
45  if (is_object($addressTotal->getTitle())) {
46  $pureData[TotalSegmentInterface::TITLE] = $addressTotal->getTitle()->render();
47  }
49  $total = $this->factory->create();
50  $total->setData($pureData);
51  $data[$addressTotal->getCode()] = $total;
52  }
53  return $data;
54  }
55 }
__construct(TotalSegmentInterfaceFactory $factory)