/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Pricing/Adjustment/Pool.php
110 строк
3 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2014 Adobe * All Rights Reserved. */ namespace Magento\Framework\Pricing\Adjustment; use Magento\Framework\Pricing\Adjustment\Factory as AdjustmentFactory; /** * Global adjustment pool model * * @api * @since 100.0.2 */ class Pool { /** * Default adjustment sort order */ const DEFAULT_SORT_ORDER = -1; /** * @var AdjustmentFactory */ protected $adjustmentFactory; /** * @var array[] */ protected $adjustments; /** * @var AdjustmentInterface[] */ protected $adjustmentInstances; /** * @param AdjustmentFactory $adjustmentFactory * @param array[] $adjustments */ public function __construct(AdjustmentFactory $adjustmentFactory, $adjustments = []) { $this->adjustmentFactory = $adjustmentFactory; $this->adjustments = $adjustments; } /** * @return AdjustmentInterface[] */ public function getAdjustments() { if (!isset($this->adjustmentInstances)) { $this->adjustmentInstances = $this->createAdjustments(array_keys($this->adjustments)); } return $this->adjustmentInstances; } /** * @param string $adjustmentCode * @return AdjustmentInterface * @throws \InvalidArgumentException */ public function getAdjustmentByCode($adjustmentCode) { if (!isset($this->adjustmentInstances)) { $this->adjustmentInstances = $this->createAdjustments(array_keys($this->adjustments)); } if (!isset($this->adjustmentInstances[$adjustmentCode])) { throw new \InvalidArgumentException(sprintf('Price adjustment "%s" is not registered', $adjustmentCode)); } return $this->adjustmentInstances[$adjustmentCode]; } /** * Instantiate adjustments * * @param string[] $adjustments * @return AdjustmentInterface[] */ protected function createAdjustments($adjustments) { $instances = []; foreach ($adjustments as $code) { if (!isset($instances[$code])) { $instances[$code] = $this->createAdjustment($code); } } return $instances; } /** * Create adjustment by code * * @param string $adjustmentCode * @return AdjustmentInterface */ protected function createAdjustment($adjustmentCode) { $adjustmentData = $this->adjustments[$adjustmentCode]; $sortOrder = isset($adjustmentData['sortOrder']) ? (int)$adjustmentData['sortOrder'] : self::DEFAULT_SORT_ORDER; return $this->adjustmentFactory->create( $adjustmentData['className'], [ 'sortOrder' => $sortOrder ] ); } }