Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductOptionProcessor.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Downloadable\Model\DownloadableOptionFactory;
13 use Magento\Framework\DataObject\Factory as DataObjectFactory;
14 
16 {
20  protected $objectFactory;
21 
25  protected $dataObjectHelper;
26 
31 
37  public function __construct(
38  DataObjectFactory $objectFactory,
40  DownloadableOptionFactory $downloadableOptionFactory
41  ) {
42  $this->objectFactory = $objectFactory;
43  $this->dataObjectHelper = $dataObjectHelper;
44  $this->downloadableOptionFactory = $downloadableOptionFactory;
45  }
46 
51  {
53  $request = $this->objectFactory->create();
54 
55  $links = $this->getDownloadableLinks($productOption);
56  if (!empty($links)) {
57  $request->addData(['links' => $links]);
58  }
59 
60  return $request;
61  }
62 
70  {
71  if ($productOption
72  && $productOption->getExtensionAttributes()
73  && $productOption->getExtensionAttributes()->getDownloadableOption()
74  ) {
75  return $productOption->getExtensionAttributes()
76  ->getDownloadableOption()
77  ->getDownloadableLinks();
78  }
79  return [];
80  }
81 
86  {
88  $downloadableOption = $this->downloadableOptionFactory->create();
89 
90  $links = $request->getLinks();
91  if (!empty($links) && is_array($links)) {
92  $this->dataObjectHelper->populateWithArray(
93  $downloadableOption,
94  ['downloadable_links' => $links],
95  \Magento\Downloadable\Api\Data\DownloadableOptionInterface::class
96  );
97 
98  return ['downloadable_option' => $downloadableOption];
99  }
100 
101  return [];
102  }
103 }
getDownloadableLinks(ProductOptionInterface $productOption)
__construct(DataObjectFactory $objectFactory, DataObjectHelper $dataObjectHelper, DownloadableOptionFactory $downloadableOptionFactory)
convertToBuyRequest(ProductOptionInterface $productOption)