| 1 |
<?php |
| 2 |
/** |
| 3 |
* Description of PriceFormulaSetFactory |
| 4 |
* |
| 5 |
* @author Ali2Woo Team |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace AliNext_Lite;; |
| 10 |
|
| 11 |
class PriceFormulaSetFactory |
| 12 |
{ |
| 13 |
private PriceFormulaFactory $PriceFormulaFactory; |
| 14 |
|
| 15 |
public function __construct(PriceFormulaFactory $PriceFormulaFactory) |
| 16 |
{ |
| 17 |
$this->PriceFormulaFactory = $PriceFormulaFactory; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* @param array $data |
| 22 |
* @return PriceFormulaSet |
| 23 |
*/ |
| 24 |
public function createFormulaSetFromData(array $data): PriceFormulaSet |
| 25 |
{ |
| 26 |
$setName = $data[PriceFormulaSet::NAME_FIELD]; |
| 27 |
$PriceFormulaDefault = $this->PriceFormulaFactory->createFormulaFromData( |
| 28 |
$data[PriceFormulaSet::DEFAULT_FORMULA_FIELD] |
| 29 |
); |
| 30 |
$ExtendedFormulas = []; |
| 31 |
foreach ($data[PriceFormulaSet::FORMULA_LIST_FIELD] as $priceFormulaDate) { |
| 32 |
$ExtendedFormulas[] = $this->PriceFormulaFactory->createFormulaFromData( |
| 33 |
$priceFormulaDate |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
return (new PriceFormulaSet()) |
| 38 |
->setName($setName) |
| 39 |
->setDefaultFormula($PriceFormulaDefault) |
| 40 |
->setExtendedFormulas($ExtendedFormulas) |
| 41 |
->setCents($data[PriceFormulaSet::PRICE_CENTS_FIELD]) |
| 42 |
->setComparedCents($data[PriceFormulaSet::PRICE_COMPARED_CENTS_FIELD]) |
| 43 |
->setUseExtendedPriceMarkup($data[PriceFormulaSet::USE_EXTENDED_PRICE_MARKUP_FIELD]) |
| 44 |
->setUseComparedPriceMarkup($data[PriceFormulaSet::USE_COMPARED_PRICE_MARKUP_FIELD]) |
| 45 |
->setAddShippingToPrice($data[PriceFormulaSet::ADD_SHIPPING_TO_PRICE_FIELD]) |
| 46 |
->setApplyPriceRulesAfterShippingCost($data[PriceFormulaSet::APPLY_PRICE_RULES_AFTER_SHIPPING_COST_FIELD]) |
| 47 |
->setPricingRulesType($data[PriceFormulaSet::PRICING_RULES_TYPE_FIELD]); |
| 48 |
} |
| 49 |
|
| 50 |
public function createFormulaSet( |
| 51 |
string $setName, PriceFormula $PriceFormulaDefault, array $ExtendedFormulas, int $cents, |
| 52 |
int $comparedCents, bool $useExtendedPriceMarkup, bool $useComparedPriceMarkup, bool $addShippingToPrice, |
| 53 |
bool $applyPriceRulesAfterShippingCost, string $pricingRulesType |
| 54 |
): PriceFormulaSet { |
| 55 |
|
| 56 |
return (new PriceFormulaSet()) |
| 57 |
->setName($setName) |
| 58 |
->setDefaultFormula($PriceFormulaDefault) |
| 59 |
->setExtendedFormulas($ExtendedFormulas) |
| 60 |
->setCents($cents) |
| 61 |
->setComparedCents($comparedCents) |
| 62 |
->setUseExtendedPriceMarkup($useExtendedPriceMarkup) |
| 63 |
->setUseComparedPriceMarkup($useComparedPriceMarkup) |
| 64 |
->setAddShippingToPrice($addShippingToPrice) |
| 65 |
->setApplyPriceRulesAfterShippingCost($applyPriceRulesAfterShippingCost) |
| 66 |
->setPricingRulesType($pricingRulesType); |
| 67 |
} |
| 68 |
} |
| 69 |
|