Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
PriceComposite Class Reference

Public Member Functions

 __construct (PriceFactory $priceFactory, array $metadata=[])
 
 getPriceCodes ()
 
 getMetadata ()
 
 createPriceObject (SaleableInterface $salableItem, $priceCode, $quantity)
 

Protected Attributes

 $priceFactory
 
 $metadata
 

Detailed Description

Composite price model

Definition at line 15 of file PriceComposite.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( PriceFactory  $priceFactory,
array  $metadata = [] 
)
Parameters
PriceFactory$priceFactory
array$metadata

Definition at line 31 of file PriceComposite.php.

32  {
33  $this->priceFactory = $priceFactory;
34  $this->metadata = $metadata;
35  }

Member Function Documentation

◆ createPriceObject()

createPriceObject ( SaleableInterface  $salableItem,
  $priceCode,
  $quantity 
)
Parameters
SaleableInterface$salableItem
string$priceCode
float$quantity
Returns
PriceInterface
Exceptions

Definition at line 62 of file PriceComposite.php.

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  }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ getMetadata()

getMetadata ( )

Returns metadata for prices

Returns
array

Definition at line 50 of file PriceComposite.php.

◆ getPriceCodes()

getPriceCodes ( )
Returns
array

Definition at line 40 of file PriceComposite.php.

41  {
42  return array_keys($this->metadata);
43  }

Field Documentation

◆ $metadata

$metadata
protected

Definition at line 25 of file PriceComposite.php.

◆ $priceFactory

$priceFactory
protected

Definition at line 20 of file PriceComposite.php.


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