Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PriceComposite.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
20  protected $priceFactory;
21 
25  protected $metadata;
26 
31  public function __construct(PriceFactory $priceFactory, array $metadata = [])
32  {
33  $this->priceFactory = $priceFactory;
34  $this->metadata = $metadata;
35  }
36 
40  public function getPriceCodes()
41  {
42  return array_keys($this->metadata);
43  }
44 
50  public function getMetadata()
51  {
52  return $this->metadata;
53  }
54 
62  public function createPriceObject(SaleableInterface $salableItem, $priceCode, $quantity)
63  {
64  if (!isset($this->metadata[$priceCode])) {
65  throw new \InvalidArgumentException($priceCode . ' is not registered in prices list');
66  }
67  $className = $this->metadata[$priceCode]['class'];
68  return $this->priceFactory->create($salableItem, $className, $quantity);
69  }
70 }
__construct(PriceFactory $priceFactory, array $metadata=[])
createPriceObject(SaleableInterface $salableItem, $priceCode, $quantity)
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31