![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/Ecombricks/InventoryBundle/Pricing/Price/BundleSelectionPrice/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See LICENSE.txt for license details. */ namespace Ecombricks\InventoryBundle\Pricing\Price\BundleSelectionPrice; /** * Bundle selection price source trait */ trait SourceTrait { /** * Get source code * * @return string|null */ protected function getSourceCode() { return $this->selection->getExtensionAttributes()->getSourceCode(); } /** * Get selection key * * @param string $field * @return string */ protected function getSelectionKey($field) { $keyParts = ['bundle-selection']; if ($this->useRegularPrice) { $keyParts[] = 'regular'; } $keyParts[] = $field; $keyParts[] = $this->selection->getSelectionId(); $keyParts[] = $this->getSourceCode(); return implode('-', $keyParts); } /** * Get value * * @return bool|float */ public function inventoryGetValue() { if (null !== $this->value) { return $this->value; } $selectionKey = $this->getSelectionKey('value'); if ($this->bundleProduct->hasData($selectionKey)) { return $this->bundleProduct->getData($selectionKey); } $priceCode = $this->useRegularPrice ? \Magento\Bundle\Pricing\Price\BundleRegularPrice::PRICE_CODE : \Magento\Bundle\Pricing\Price\FinalPrice::PRICE_CODE; if ($this->bundleProduct->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) { $value = $this->priceInfo->getPrice($priceCode)->getValue(); } else { $selectionPriceValue = $this->selection->getSelectionPriceValue(); if ($this->selection->getSelectionPriceType()) { $price = $this->bundleProduct->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE)->getValue(); $product = clone $this->bundleProduct; $product->setFinalPrice($price); $this->eventManager->dispatch( 'catalog_product_get_final_price', [ 'product' => $product, 'qty' => $this->bundleProduct->getQty(), ] ); $value = $this->useRegularPrice ? $product->getData('price') : $product->getData('final_price') * ($selectionPriceValue / 100); } else { $value = $this->priceCurrency->convert($selectionPriceValue); } } if (!$this->useRegularPrice) { $value = $this->discountCalculator->calculateDiscount($this->bundleProduct, $value); } $this->value = $this->priceCurrency->round($value); $this->bundleProduct->setData($selectionKey, $this->value); return $this->value; } /** * Get amount * * @return \Magento\Framework\Pricing\Amount\AmountInterface */ public function inventoryGetAmount() { $value = $this->getValue(); if (isset($this->amount[$value])) { return $this->amount[$value]; } $selectionKey = $this->getSelectionKey('amount'); if ($this->bundleProduct->hasData($selectionKey)) { return $this->bundleProduct->getData($selectionKey); } $exclude = null; if ($this->getProduct()->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { $exclude = $this->excludeAdjustment; } $this->amount[$value] = $this->calculator->getAmount($value, $this->getProduct(), $exclude); $this->bundleProduct->setData($selectionKey, $this->amount[$value]); return $this->amount[$value]; } }