From 5f13fb2da67db2fb8ee61eaa77d1464e2725d299 Mon Sep 17 00:00:00 2001 From: klg Date: Wed, 6 Mar 2019 15:05:00 +0100 Subject: [PATCH 1/6] rebase to magenerds-master --- Block/AfterPrice.php | 9 +++++ Helper/Data.php | 82 ++++++++++++++++++++++++++++++++++++++------ etc/module.xml | 2 +- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/Block/AfterPrice.php b/Block/AfterPrice.php index f5a2711..e378ac3 100755 --- a/Block/AfterPrice.php +++ b/Block/AfterPrice.php @@ -99,4 +99,13 @@ public function getBasePrice() { return $this->_helper->getBasePriceText($this->getProduct()); } + + /** + * Returns the base price for tier prices + * @return array + */ + public function getTierBasePrices(): array + { + return $this->_helper->getTierBasePricesText($this->getProduct(), true); + } } \ No newline at end of file diff --git a/Helper/Data.php b/Helper/Data.php index 238d3de..eee7fd5 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -91,6 +91,13 @@ public function getConversion($product) return 1; } + private function getBasepriceLayoutTemplate(): string { + return $this->scopeConfig->getValue( + 'baseprice/general/template', + ScopeInterface::SCOPE_STORE + ); + } + /** * Returns the base price text according to the configured template * @@ -99,11 +106,6 @@ public function getConversion($product) */ public function getBasePriceText(Product $product) { - $template = $this->scopeConfig->getValue( - 'baseprice/general/template', - ScopeInterface::SCOPE_STORE - ); - $basePrice = $this->getBasePrice($product); if (!$basePrice) return ''; @@ -111,10 +113,61 @@ public function getBasePriceText(Product $product) return str_replace( '{REF_UNIT}', $this->getReferenceUnit($product), str_replace( '{REF_AMOUNT}', $this->getReferenceAmount($product), str_replace( - '{BASE_PRICE}', $this->priceHelper->currency($basePrice), $template) + '{BASE_PRICE}', $this->priceHelper->currency($basePrice), $this->getBasepriceLayoutTemplate()) )); } + /** + * Returns an array with the base prices for all tier prices. Uses the tier price id as index. + * @param Product $product + * + * @return array + */ + public function getTierBasePricesText(Product $product):array + { + $tierPricesTexts = []; + foreach ($product->getTierPrice() as $tier) { + $basePrice = $this->getBasePrice($product, $tier['price']); + + if (!$basePrice) continue; + + $tierPricesTexts[$tier['price_id']] = str_replace( + '{REF_UNIT}', $this->getReferenceUnit($product), str_replace( + '{REF_AMOUNT}', $this->getReferenceAmount($product), str_replace( + '{BASE_PRICE}', $this->priceHelper->currency($basePrice), $this->getBasepriceLayoutTemplate()) + )); + } + + return $tierPricesTexts; + } + + /** + * Returns the base price for a tier price by its ID. + * @param Product $product + * @param int $tierPriceID + * + * @return string + */ + public function getTierBasePriceText(Product $product, int $tierPriceID): string + { + foreach ($product->getTierPrice() as $tier) { + if( (int) $tier['price_id'] === $tierPriceID) { + $basePrice = $this->getBasePrice($product, $tier['price']); + + if ( ! $basePrice) { + break; + } + + return str_replace( + '{REF_UNIT}', $this->getReferenceUnit($product), str_replace( + '{REF_AMOUNT}', $this->getReferenceAmount($product), str_replace( + '{BASE_PRICE}', $this->priceHelper->currency($basePrice), $this->getBasepriceLayoutTemplate()) + )); + } + } + return ''; + } + /** * Returns the reference unit of current product * @@ -122,7 +175,7 @@ public function getBasePriceText(Product $product) */ public function getReferenceUnit(Product $product) { - return $product->getAttributeText('baseprice_reference_unit'); + return __($product->getAttributeText('baseprice_reference_unit')); } /** @@ -137,12 +190,19 @@ public function getReferenceAmount(Product $product) /** * Calculates the base price for given product + * @param Product $product + * @param float $amount Optional amount. Used to calculate the tier prices. * - * @return float|string + * @return float */ - public function getBasePrice(Product $product) + public function getBasePrice(Product $product, float $amount = 0) { - $productPrice = round($product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(), PriceCurrencyInterface::DEFAULT_PRECISION); + $price = $amount; + if($amount == 0) { + $price = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); + } + + $productPrice = round($price, PriceCurrencyInterface::DEFAULT_PRECISION); $conversion = $this->getConversion($product); $referenceAmount = $product->getData('baseprice_reference_amount'); $productAmount = $product->getData('baseprice_product_amount'); @@ -152,6 +212,6 @@ public function getBasePrice(Product $product) $basePrice = $productPrice * $conversion * $referenceAmount / $productAmount; } - return $basePrice; + return (float) $basePrice; } } diff --git a/etc/module.xml b/etc/module.xml index a7b8ecd..b1250b5 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -18,7 +18,7 @@ */ --> - + From b869307a3dff204c5644aec6d6cfb9e5456eb5b8 Mon Sep 17 00:00:00 2001 From: klg Date: Wed, 6 Mar 2019 15:05:40 +0100 Subject: [PATCH 2/6] reset --- etc/module.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/module.xml b/etc/module.xml index b1250b5..a7b8ecd 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -18,7 +18,7 @@ */ --> - + From 0405ef676a80c2b74c07176c639df38934e8e8bc Mon Sep 17 00:00:00 2001 From: Simon Sippert Date: Mon, 6 May 2019 17:08:23 +0200 Subject: [PATCH 3/6] Set new copyright year --- Block/Adminhtml/Form/Field/Unit.php | 6 +++--- .../System/Config/Form/Field/ConversionMapping.php | 6 +++--- Block/AfterPrice.php | 6 +++--- Helper/Data.php | 4 ++-- Model/Plugin/AfterPrice.php | 4 ++-- Model/Plugin/ConfigurablePrice.php | 6 +++--- Model/Plugin/Grouped.php | 6 +++--- Setup/InstallData.php | 4 ++-- etc/acl.xml | 6 +++--- etc/adminhtml/system.xml | 6 +++--- etc/config.xml | 6 +++--- etc/di.xml | 6 +++--- etc/module.xml | 4 ++-- registration.php | 6 +++--- view/frontend/templates/afterprice.phtml | 6 +++--- view/frontend/templates/configurable/afterprice.phtml | 4 ++-- 16 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Block/Adminhtml/Form/Field/Unit.php b/Block/Adminhtml/Form/Field/Unit.php index 4c8dd9e..3fe9598 100644 --- a/Block/Adminhtml/Form/Field/Unit.php +++ b/Block/Adminhtml/Form/Field/Unit.php @@ -11,8 +11,8 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Block - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ namespace Magenerds\BasePrice\Block\Adminhtml\Form\Field; @@ -77,4 +77,4 @@ public function _toHtml() public function setInputName($value) { return $this->setName($value); } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/System/Config/Form/Field/ConversionMapping.php b/Block/Adminhtml/System/Config/Form/Field/ConversionMapping.php index a781ff8..185b523 100644 --- a/Block/Adminhtml/System/Config/Form/Field/ConversionMapping.php +++ b/Block/Adminhtml/System/Config/Form/Field/ConversionMapping.php @@ -11,8 +11,8 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Block - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ namespace Magenerds\BasePrice\Block\Adminhtml\System\Config\Form\Field; @@ -127,4 +127,4 @@ public function renderCellTemplate($columnName) return parent::renderCellTemplate($columnName); } -} \ No newline at end of file +} diff --git a/Block/AfterPrice.php b/Block/AfterPrice.php index f5a2711..b1a79c9 100755 --- a/Block/AfterPrice.php +++ b/Block/AfterPrice.php @@ -11,8 +11,8 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Block - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ namespace Magenerds\BasePrice\Block; @@ -99,4 +99,4 @@ public function getBasePrice() { return $this->_helper->getBasePriceText($this->getProduct()); } -} \ No newline at end of file +} diff --git a/Helper/Data.php b/Helper/Data.php index 238d3de..142a25d 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -11,8 +11,8 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Helper - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ namespace Magenerds\BasePrice\Helper; diff --git a/Model/Plugin/AfterPrice.php b/Model/Plugin/AfterPrice.php index 18f5566..c1d2e33 100644 --- a/Model/Plugin/AfterPrice.php +++ b/Model/Plugin/AfterPrice.php @@ -11,8 +11,8 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Model - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ namespace Magenerds\BasePrice\Model\Plugin; diff --git a/Model/Plugin/ConfigurablePrice.php b/Model/Plugin/ConfigurablePrice.php index 321a946..1a0c4f1 100644 --- a/Model/Plugin/ConfigurablePrice.php +++ b/Model/Plugin/ConfigurablePrice.php @@ -11,8 +11,8 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Model - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ namespace Magenerds\BasePrice\Model\Plugin; @@ -81,4 +81,4 @@ public function afterGetJsonConfig(\Magento\ConfigurableProduct\Block\Product\Vi return $this->_jsonEncoder->encode($config); } -} \ No newline at end of file +} diff --git a/Model/Plugin/Grouped.php b/Model/Plugin/Grouped.php index d75d7e7..e93fa76 100644 --- a/Model/Plugin/Grouped.php +++ b/Model/Plugin/Grouped.php @@ -11,8 +11,8 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Model - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ namespace Magenerds\BasePrice\Model\Plugin; @@ -58,4 +58,4 @@ public function getAssociatedProducts($product) } return $product->getData($this->_keyAssociatedProducts); } -} \ No newline at end of file +} diff --git a/Setup/InstallData.php b/Setup/InstallData.php index 8cde376..cd47451 100644 --- a/Setup/InstallData.php +++ b/Setup/InstallData.php @@ -11,8 +11,8 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Setup - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ namespace Magenerds\BasePrice\Setup; diff --git a/etc/acl.xml b/etc/acl.xml index 80c0ae0..80f2c5f 100644 --- a/etc/acl.xml +++ b/etc/acl.xml @@ -13,8 +13,8 @@ * @package Magenerds_BasePrice * @subpackage etc * @author Florian Sydekum - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ */ --> @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 7764826..a43867a 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -13,8 +13,8 @@ * @package Magenerds_BasePrice * @subpackage etc * @author Florian Sydekum - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ */ --> @@ -44,4 +44,4 @@ - \ No newline at end of file + diff --git a/etc/config.xml b/etc/config.xml index c0fa085..c38da83 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -13,8 +13,8 @@ * @package Magenerds_BasePrice * @subpackage etc * @author Florian Sydekum - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ */ --> @@ -26,4 +26,4 @@ - \ No newline at end of file + diff --git a/etc/di.xml b/etc/di.xml index f9f9ec0..9b47a49 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -13,8 +13,8 @@ * @package Magenerds_BasePrice * @subpackage etc * @author Florian Sydekum - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ */ --> @@ -25,4 +25,4 @@ - \ No newline at end of file + diff --git a/etc/module.xml b/etc/module.xml index a7b8ecd..4db97ab 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -13,8 +13,8 @@ * @package Magenerds_BasePrice * @subpackage etc * @author Florian Sydekum - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ */ --> diff --git a/registration.php b/registration.php index fc285f2..4b6b6c0 100644 --- a/registration.php +++ b/registration.php @@ -11,12 +11,12 @@ * @category Magenerds * @package Magenerds_BasePrice * @subpackage Module - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ * @author Florian Sydekum */ \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magenerds_BasePrice', __DIR__ -); \ No newline at end of file +); diff --git a/view/frontend/templates/afterprice.phtml b/view/frontend/templates/afterprice.phtml index bbf4492..1e78ecb 100755 --- a/view/frontend/templates/afterprice.phtml +++ b/view/frontend/templates/afterprice.phtml @@ -12,8 +12,8 @@ * @package Magenerds_BasePrice * @subpackage view * @author Florian Sydekum - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ */ /** @@ -24,4 +24,4 @@
getBasePrice() ?>
- \ No newline at end of file + diff --git a/view/frontend/templates/configurable/afterprice.phtml b/view/frontend/templates/configurable/afterprice.phtml index b29840d..3ea6702 100755 --- a/view/frontend/templates/configurable/afterprice.phtml +++ b/view/frontend/templates/configurable/afterprice.phtml @@ -12,8 +12,8 @@ * @package Magenerds_BasePrice * @subpackage view * @author Florian Sydekum - * @copyright Copyright (c) 2017 TechDivision GmbH (http://www.techdivision.com) - * @link http://www.techdivision.com/ + * @copyright Copyright (c) 2019 TechDivision GmbH (https://www.techdivision.com) + * @link https://www.techdivision.com/ */ /** From d1e6e4d16733cc2d5afeb30b48a78b74b24e8d67 Mon Sep 17 00:00:00 2001 From: Simon Sippert Date: Wed, 10 Jul 2019 14:54:11 +0200 Subject: [PATCH 4/6] Whitespace --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db888c2..1e4d328 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ Website: http://www.magenerds.com/magento-2-extensions/base-price/ -Documentation: http://doc.magenerds.com/base-price/ \ No newline at end of file +Documentation: http://doc.magenerds.com/base-price/ From 465226fdb2b8c9be752b42743abc56d07a5c848d Mon Sep 17 00:00:00 2001 From: bst2002git Date: Fri, 18 Oct 2019 12:05:38 +0200 Subject: [PATCH 5/6] . --- Block/AfterPrice.php | 4 ---- view/frontend/templates/afterprice.phtml | 6 ------ 2 files changed, 10 deletions(-) diff --git a/Block/AfterPrice.php b/Block/AfterPrice.php index 9620c2d..a86ffdb 100755 --- a/Block/AfterPrice.php +++ b/Block/AfterPrice.php @@ -129,9 +129,6 @@ public function getBasePrice() { return $this->_helper->getBasePriceText($this->getProduct()); } -<<<<<<< HEAD -} -======= /** * Returns the base price for tier prices @@ -142,4 +139,3 @@ public function getTierBasePrices(): array return $this->_helper->getTierBasePricesText($this->getProduct(), true); } } ->>>>>>> 9b88813fe8eeefb7b02c7bb083b9fbed4951edb2 diff --git a/view/frontend/templates/afterprice.phtml b/view/frontend/templates/afterprice.phtml index a90dc6c..96d2a19 100755 --- a/view/frontend/templates/afterprice.phtml +++ b/view/frontend/templates/afterprice.phtml @@ -21,11 +21,6 @@ */ ?> isEnabled()): ?> -<<<<<<< HEAD -
- getBasePrice() ?> -
-=======
getBasePrice() ?>
isConfigurable()): ?> ->>>>>>> 9b88813fe8eeefb7b02c7bb083b9fbed4951edb2 From e19dbdefe02e7647ab4cef06303fe68f36b2c0c0 Mon Sep 17 00:00:00 2001 From: bst2002git Date: Fri, 18 Oct 2019 13:00:57 +0200 Subject: [PATCH 6/6] . --- Block/AfterPrice.php | 4 ---- Helper/Data.php | 8 -------- 2 files changed, 12 deletions(-) diff --git a/Block/AfterPrice.php b/Block/AfterPrice.php index 40fb475..a86ffdb 100755 --- a/Block/AfterPrice.php +++ b/Block/AfterPrice.php @@ -138,8 +138,4 @@ public function getTierBasePrices(): array { return $this->_helper->getTierBasePricesText($this->getProduct(), true); } -<<<<<<< HEAD } -======= -} ->>>>>>> b869307a3dff204c5644aec6d6cfb9e5456eb5b8 diff --git a/Helper/Data.php b/Helper/Data.php index cffde9a..04cddde 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -144,20 +144,12 @@ public function getTierBasePricesText(Product $product):array /** * Returns the base price for a tier price by its ID. -<<<<<<< HEAD * @param ProductInterface $product -======= - * @param Product $product ->>>>>>> b869307a3dff204c5644aec6d6cfb9e5456eb5b8 * @param int $tierPriceID * * @return string */ -<<<<<<< HEAD public function getTierBasePriceText(ProductInterface $product, int $tierPriceID): string -======= - public function getTierBasePriceText(Product $product, int $tierPriceID): string ->>>>>>> b869307a3dff204c5644aec6d6cfb9e5456eb5b8 { foreach ($product->getTierPrice() as $tier) { if( (int) $tier['price_id'] === $tierPriceID) {