Skip to content

Commit

Permalink
[EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
 - merged latest code from mainline branch
  • Loading branch information
magento-engcom-team authored Apr 11, 2019
2 parents 350cf1e + f7ac18b commit 4dbcbd3
Show file tree
Hide file tree
Showing 44 changed files with 1,124 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Bundle\Block\DataProviders;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Pricing\Price\TierPrice;
use Magento\Framework\Pricing\Render;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Framework\View\LayoutInterface;

/**
* Provides additional data for bundle options
*/
class OptionPriceRenderer implements ArgumentInterface
{
/**
* Parent layout of the block
*
* @var LayoutInterface
*/
private $layout;

/**
* @param LayoutInterface $layout
*/
public function __construct(LayoutInterface $layout)
{
$this->layout = $layout;
}

/**
* Format tier price string
*
* @param Product $selection
* @param array $arguments
* @return string
*/
public function renderTierPrice(Product $selection, array $arguments = []): string
{
if (!array_key_exists('zone', $arguments)) {
$arguments['zone'] = Render::ZONE_ITEM_OPTION;
}

$priceHtml = '';

/** @var Render $priceRender */
$priceRender = $this->layout->getBlock('product.price.render.default');
if ($priceRender !== false) {
$priceHtml = $priceRender->render(
TierPrice::PRICE_CODE,
$selection,
$arguments
);
}

return $priceHtml;
}
}
70 changes: 38 additions & 32 deletions app/code/Magento/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;

/**
* Bundle product type price model
*
* @api
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* @since 100.0.2
*/
class Price extends \Magento\Catalog\Model\Product\Type\Price
Expand Down Expand Up @@ -180,9 +183,9 @@ protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product
/**
* Get product final price
*
* @param float $qty
* @param \Magento\Catalog\Model\Product $product
* @return float
* @param float $qty
* @param \Magento\Catalog\Model\Product $product
* @return float
*/
public function getFinalPrice($qty, $product)
{
Expand All @@ -207,9 +210,9 @@ public function getFinalPrice($qty, $product)
* Returns final price of a child product
*
* @param \Magento\Catalog\Model\Product $product
* @param float $productQty
* @param float $productQty
* @param \Magento\Catalog\Model\Product $childProduct
* @param float $childProductQty
* @param float $childProductQty
* @return float
*/
public function getChildFinalPrice($product, $productQty, $childProduct, $childProductQty)
Expand All @@ -220,10 +223,10 @@ public function getChildFinalPrice($product, $productQty, $childProduct, $childP
/**
* Retrieve Price considering tier price
*
* @param \Magento\Catalog\Model\Product $product
* @param string|null $which
* @param bool|null $includeTax
* @param bool $takeTierPrice
* @param \Magento\Catalog\Model\Product $product
* @param string|null $which
* @param bool|null $includeTax
* @param bool $takeTierPrice
* @return float|array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
Expand Down Expand Up @@ -402,8 +405,8 @@ public function getOptions($product)
*
* @param \Magento\Catalog\Model\Product $bundleProduct
* @param \Magento\Catalog\Model\Product $selectionProduct
* @param float|null $selectionQty
* @param null|bool $multiplyQty Whether to multiply selection's price by its quantity
* @param float|null $selectionQty
* @param null|bool $multiplyQty Whether to multiply selection's price by its quantity
* @return float
*
* @see \Magento\Bundle\Model\Product\Price::getSelectionFinalTotalPrice()
Expand All @@ -418,7 +421,7 @@ public function getSelectionPrice($bundleProduct, $selectionProduct, $selectionQ
*
* @param \Magento\Catalog\Model\Product $bundleProduct
* @param \Magento\Catalog\Model\Product $selectionProduct
* @param float $qty
* @param float $qty
* @return float
*/
public function getSelectionPreFinalPrice($bundleProduct, $selectionProduct, $qty = null)
Expand All @@ -427,15 +430,14 @@ public function getSelectionPreFinalPrice($bundleProduct, $selectionProduct, $qt
}

/**
* Calculate final price of selection
* with take into account tier price
* Calculate final price of selection with take into account tier price
*
* @param \Magento\Catalog\Model\Product $bundleProduct
* @param \Magento\Catalog\Model\Product $selectionProduct
* @param float $bundleQty
* @param float $selectionQty
* @param bool $multiplyQty
* @param bool $takeTierPrice
* @param \Magento\Catalog\Model\Product $bundleProduct
* @param \Magento\Catalog\Model\Product $selectionProduct
* @param float $bundleQty
* @param float $selectionQty
* @param bool $multiplyQty
* @param bool $takeTierPrice
* @return float
*/
public function getSelectionFinalTotalPrice(
Expand All @@ -454,7 +456,11 @@ public function getSelectionFinalTotalPrice(
}

if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
$price = $selectionProduct->getFinalPrice($takeTierPrice ? $selectionQty : 1);
$totalQty = $bundleQty * $selectionQty;
if (!$takeTierPrice || $totalQty === 0) {
$totalQty = 1;
}
$price = $selectionProduct->getFinalPrice($totalQty);
} else {
if ($selectionProduct->getSelectionPriceType()) {
// percent
Expand Down Expand Up @@ -485,10 +491,10 @@ public function getSelectionFinalTotalPrice(
/**
* Apply tier price for bundle
*
* @param \Magento\Catalog\Model\Product $product
* @param float $qty
* @param float $finalPrice
* @return float
* @param \Magento\Catalog\Model\Product $product
* @param float $qty
* @param float $finalPrice
* @return float
*/
protected function _applyTierPrice($product, $qty, $finalPrice)
{
Expand All @@ -509,9 +515,9 @@ protected function _applyTierPrice($product, $qty, $finalPrice)
/**
* Get product tier price by qty
*
* @param float $qty
* @param \Magento\Catalog\Model\Product $product
* @return float|array
* @param float $qty
* @param \Magento\Catalog\Model\Product $product
* @return float|array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
Expand Down Expand Up @@ -605,11 +611,11 @@ public function getTierPrice($qty, $product)
/**
* Calculate and apply special price
*
* @param float $finalPrice
* @param float $specialPrice
* @param float $finalPrice
* @param float $specialPrice
* @param string $specialPriceFrom
* @param string $specialPriceTo
* @param mixed $store
* @param mixed $store
* @return float
*/
public function calculateSpecialPrice(
Expand All @@ -634,7 +640,7 @@ public function calculateSpecialPrice(
*
* @param /Magento/Catalog/Model/Product $bundleProduct
* @param float|string $price
* @param int $bundleQty
* @param int $bundleQty
* @return float
*/
public function getLowestPrice($bundleProduct, $price, $bundleQty = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,67 @@
<requiredEntity createDataKey="simpleProduct4"/>
</createData>
</actionGroup>
<actionGroup name="AdminCreateApiDynamicBundleProductAllOptionTypesActionGroup">
<arguments>
<argument name="productName" defaultValue="Api Dynamic Bundle Product" type="string"/>
</arguments>
<!-- Create sub ctegory -->
<createData entity="SimpleSubCategory" stepKey="createSubCategory"/>
<!-- Create simple products -->
<createData entity="SimpleProduct2" stepKey="simpleProduct1">
<field key="price">10</field>
<requiredEntity createDataKey="createSubCategory"/>
</createData>
<createData entity="SimpleProduct2" stepKey="simpleProduct2">
<field key="price">20</field>
<requiredEntity createDataKey="createSubCategory"/>
</createData>
<!-- Create Bundle product -->
<createData entity="ApiBundleProduct" stepKey="createBundleProduct">
<field key="name">{{productName}}</field>
<requiredEntity createDataKey="createSubCategory"/>
</createData>
<createData entity="DropDownBundleOption" stepKey="createDropDownBundleOption">
<requiredEntity createDataKey="createBundleProduct"/>
<field key="title">Drop-down Option</field>
</createData>
<createData entity="RadioButtonsOption" stepKey="createBundleRadioButtonsOption">
<requiredEntity createDataKey="createBundleProduct"/>
<field key="title">Radio Buttons Option</field>
</createData>
<createData entity="CheckboxOption" stepKey="createBundleCheckboxOption">
<requiredEntity createDataKey="createBundleProduct"/>
<field key="title">Checkbox Option</field>
</createData>
<createData entity="ApiBundleLink" stepKey="linkCheckboxOptionToProduct1">
<requiredEntity createDataKey="createBundleProduct"/>
<requiredEntity createDataKey="createBundleCheckboxOption"/>
<requiredEntity createDataKey="simpleProduct1"/>
</createData>
<createData entity="ApiBundleLink" stepKey="linkCheckboxOptionToProduct2">
<requiredEntity createDataKey="createBundleProduct"/>
<requiredEntity createDataKey="createBundleCheckboxOption"/>
<requiredEntity createDataKey="simpleProduct2"/>
</createData>
<createData entity="ApiBundleLink" stepKey="linkDropDownOptionToProduct1">
<requiredEntity createDataKey="createBundleProduct"/>
<requiredEntity createDataKey="createDropDownBundleOption"/>
<requiredEntity createDataKey="simpleProduct1"/>
</createData>
<createData entity="ApiBundleLink" stepKey="linkDropDownOptionToProduct2">
<requiredEntity createDataKey="createBundleProduct"/>
<requiredEntity createDataKey="createDropDownBundleOption"/>
<requiredEntity createDataKey="simpleProduct2"/>
</createData>
<createData entity="ApiBundleLink" stepKey="linkRadioButtonsOptionToProduct1">
<requiredEntity createDataKey="createBundleProduct"/>
<requiredEntity createDataKey="createBundleRadioButtonsOption"/>
<requiredEntity createDataKey="simpleProduct1"/>
</createData>
<createData entity="ApiBundleLink" stepKey="linkRadioButtonsOptionToProduct2">
<requiredEntity createDataKey="createBundleProduct"/>
<requiredEntity createDataKey="createBundleRadioButtonsOption"/>
<requiredEntity createDataKey="simpleProduct2"/>
</createData>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
<element name="addToCartConfigured" type="button" selector="#product-addtocart-button" timeout="30"/>
<element name="updateCart" type="button" selector="#product-updatecart-button" timeout="30"/>
<element name="configuredPrice" type="block" selector=".price-configured_price .price"/>
<element name="dropDownOptionInput" type="select" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//select" parameterized="true"/>
<element name="dropDownOptionTierPrices" type="text" selector="//label//span[contains(text(), '{{optionName}}')]/../..//div[@class='control']//div[@class='option-tier-prices']" parameterized="true"/>
<element name="radioButtonOptionLabel" type="text" selector="//label//span[contains(text(), '{{optionName}}')]/../..//div[@class='control']//div[@class='field choice']//label[contains(.,'{{productName}}')]" parameterized="true"/>
<element name="checkboxOptionLabel" type="text" selector="//label//span[contains(text(), '{{optionName}}')]/../..//div[@class='control']//div[@class='field choice']//label[contains(.,'{{productName}}')]" parameterized="true"/>
</section>
</sections>
Loading

0 comments on commit 4dbcbd3

Please sign in to comment.