Skip to content

Commit

Permalink
Merge branch '2.4-develop' into ref-QuickSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel da Gama committed Jan 12, 2021
2 parents 332ef5d + 63434d2 commit 2561d07
Show file tree
Hide file tree
Showing 260 changed files with 8,260 additions and 909 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ indent_size = 2

[{composer, auth}.json]
indent_size = 4

[db_schema_whitelist.json]
indent_size = 4
trim_trailing_whitespace = false
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* getPagerVisibility()
* getVarNamePage()
*/
$numColumns = count($block->getColumns());

/**
* @var \Magento\Backend\Block\Widget\Grid\Extended $block
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
*/
$numColumns = count($block->getColumns());

?>
<?php if ($block->getCollection()): ?>
<?php if ($block->canDisplayContainer()): ?>
Expand Down Expand Up @@ -285,7 +286,9 @@ $numColumns = count($block->getColumns());
</table>

</div>
<?php if ($block->canDisplayContainer()): ?>
</div>
<?php endif; ?>
<?php
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
$jsonHelper = $block->getData('jsonHelper');
Expand Down
151 changes: 107 additions & 44 deletions app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\Bundle\Model\Sales\Order\Pdf\Items;

use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\DataObject;
use Magento\Framework\Filesystem;
use Magento\Framework\Filter\FilterManager;
use Magento\Framework\Model\Context;
Expand Down Expand Up @@ -69,50 +70,52 @@ public function __construct(
}

/**
* Draw item line
* Draw bundle product item line
*
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function draw()
{
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$draw = $this->drawChildrenItems();
$draw = $this->drawCustomOptions($draw);

$page = $this->getPdf()->drawLineBlocks($this->getPage(), $draw, ['table_header' => true]);

$this->setPage($page);
}

/**
* Draw bundle product children items
*
* @return array
*/
private function drawChildrenItems(): array
{
$this->_setFontRegular();
$items = $this->getChildren($item);

$prevOptionId = '';
$drawItems = [];

foreach ($items as $childItem) {
$line = [];

$optionId = 0;
$lines = [];
foreach ($this->getChildren($this->getItem()) as $childItem) {
$index = array_key_last($lines) !== null ? array_key_last($lines) + 1 : 0;
$attributes = $this->getSelectionAttributes($childItem);
if (is_array($attributes)) {
$optionId = $attributes['option_id'];
} else {
$optionId = 0;
}

if (!isset($drawItems[$optionId])) {
$drawItems[$optionId] = ['lines' => [], 'height' => 15];
}

if ($childItem->getOrderItem()->getParentItem() && $prevOptionId != $attributes['option_id']) {
$line[0] = [
$lines[$index][] = [
'font' => 'italic',
'text' => $this->string->split($attributes['option_label'], 45, true, true),
'feed' => 35,
];

$drawItems[$optionId] = ['lines' => [$line], 'height' => 15];

$line = [];
$index++;
$prevOptionId = $attributes['option_id'];
}

Expand All @@ -124,35 +127,97 @@ public function draw()
$feed = 35;
$name = $childItem->getName();
}
$line[] = ['text' => $this->string->split($name, 35, true, true), 'feed' => $feed];
$lines[$index][] = ['text' => $this->string->split($name, 35, true, true), 'feed' => $feed];

// draw SKUs
if (!$childItem->getOrderItem()->getParentItem()) {
$text = [];
foreach ($this->string->split($item->getSku(), 17) as $part) {
$text[] = $part;
}
$line[] = ['text' => $text, 'feed' => 255];
}
$lines = $this->drawSkus($childItem, $lines);

// draw prices
if ($this->canShowPriceInfo($childItem)) {
$price = $order->formatPriceTxt($childItem->getPrice());
$line[] = ['text' => $price, 'feed' => 395, 'font' => 'bold', 'align' => 'right'];
$line[] = ['text' => $childItem->getQty() * 1, 'feed' => 435, 'font' => 'bold'];
$lines = $this->drawPrices($childItem, $lines);
}
$drawItems[$optionId]['lines'] = $lines;

$tax = $order->formatPriceTxt($childItem->getTaxAmount());
$line[] = ['text' => $tax, 'feed' => 495, 'font' => 'bold', 'align' => 'right'];
return $drawItems;
}

$row_total = $order->formatPriceTxt($childItem->getRowTotal());
$line[] = ['text' => $row_total, 'feed' => 565, 'font' => 'bold', 'align' => 'right'];
/**
* Draw sku parts
*
* @param DataObject $childItem
* @param array $lines
* @return array
*/
private function drawSkus(DataObject $childItem, array $lines): array
{
$index = array_key_last($lines);
if (!$childItem->getOrderItem()->getParentItem()) {
$text = [];
foreach ($this->string->split($this->getItem()->getSku(), 17) as $part) {
$text[] = $part;
}
$lines[$index][] = ['text' => $text, 'feed' => 255];
}

return $lines;
}

$drawItems[$optionId]['lines'][] = $line;
/**
* Draw prices for bundle product children items
*
* @param DataObject $childItem
* @param array $lines
* @return array
*/
private function drawPrices(DataObject $childItem, array $lines): array
{
$index = array_key_last($lines);
if ($this->canShowPriceInfo($childItem)) {
$lines[$index][] = ['text' => $childItem->getQty() * 1, 'feed' => 435, 'align' => 'right'];

$tax = $this->getOrder()->formatPriceTxt($childItem->getTaxAmount());
$lines[$index][] = ['text' => $tax, 'feed' => 495, 'font' => 'bold', 'align' => 'right'];

$item = $this->getItem();
$this->_item = $childItem;
$feedPrice = 380;
$feedSubtotal = $feedPrice + 185;
foreach ($this->getItemPricesForDisplay() as $priceData) {
if (isset($priceData['label'])) {
// draw Price label
$lines[$index][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$index][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$index++;
}
// draw Price
$lines[$index][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$index][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$index++;
}
$this->_item = $item;
}

// custom options
$options = $item->getOrderItem()->getProductOptions();
return $lines;
}

/**
* Draw bundle product custom options
*
* @param array $draw
* @return array
*/
private function drawCustomOptions(array $draw): array
{
$options = $this->getItem()->getOrderItem()->getProductOptions();
if ($options && isset($options['options'])) {
foreach ($options['options'] as $option) {
$lines = [];
Expand Down Expand Up @@ -180,12 +245,10 @@ public function draw()
$lines[][] = ['text' => $text, 'feed' => 40];
}

$drawItems[] = ['lines' => $lines, 'height' => 15];
$draw[] = ['lines' => $lines, 'height' => 15];
}
}

$page = $pdf->drawLineBlocks($page, $drawItems, ['table_header' => true]);

$this->setPage($page);
return $draw;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ public function create(
$quantity,
array $arguments = []
) {
$quantity = $quantity ? (float)$quantity : 1.;
$selection->setQty($quantity);

$arguments['bundleProduct'] = $bundleProduct;
$arguments['saleableItem'] = $selection;
$arguments['quantity'] = $quantity ? (float)$quantity : 1.;
$arguments['quantity'] = $quantity;

return $this->objectManager->create(self::SELECTION_CLASS_DEFAULT, $arguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@
<!-- Switch from default attribute set to new attribute set -->
<amOnPage url="{{AdminProductCreatePage.url('4', 'bundle')}}" stepKey="goToNewProductPage"/>
<waitForPageLoad stepKey="wait2"/>
<click selector="{{AdminProductFormSection.attributeSet}}" stepKey="startEditAttrSet"/>
<fillField selector="{{AdminProductFormSection.attributeSetFilter}}" userInput="{{ProductAttributeFrontendLabel.label}}" stepKey="searchForAttrSet"/>
<click selector="{{AdminProductFormSection.attributeSetFilterResult}}" stepKey="selectAttrSet"/>

<actionGroup ref="AdminSelectAttributeSetOnEditProductPageActionGroup" stepKey="startEditAttrSet">
<argument name="attributeSet" value="{{ProductAttributeFrontendLabel.label}}"/>
</actionGroup>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="searchForAttrSet"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="selectAttrSet"/>

<fillField selector="{{AdminProductFormBundleSection.productName}}" userInput="{{BundleProduct.name}}" stepKey="fillProductName"/>
<fillField selector="{{AdminProductFormBundleSection.productSku}}" userInput="{{BundleProduct.sku}}" stepKey="fillProductSku"/>

Expand All @@ -64,9 +68,11 @@
<click selector="{{AdminProductFiltersSection.attributeSetOfFirstRow(ProductAttributeFrontendLabel.label)}}" stepKey="clickAttributeSet2"/>
<waitForPageLoad stepKey="waitForPageLoad2"/>

<click selector="{{AdminProductFormSection.attributeSet}}" stepKey="startEditAttrSet2"/>
<fillField selector="{{AdminProductFormSection.attributeSetFilter}}" userInput="{{BundleProduct.defaultAttribute}}" stepKey="searchForAttrSet2"/>
<click selector="{{AdminProductFormSection.attributeSetFilterResult}}" stepKey="selectAttrSet2"/>
<actionGroup ref="AdminSelectAttributeSetOnEditProductPageActionGroup" stepKey="startEditAttrSet2">
<argument name="attributeSet" value="{{BundleProduct.defaultAttribute}}"/>
</actionGroup>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="searchForAttrSet2"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="selectAttrSet2"/>

<!--save the product/published by default-->
<actionGroup ref="AdminProductFormSaveActionGroup" stepKey="clickSaveButton2"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@
<checkOption selector="{{AdminProductFormBundleSection.enableDisableToggle}}" stepKey="clickOnEnableDisableToggleAgain"/>

<!--Apply Attribute Set-->
<click selector="{{AdminProductFormSection.attributeSet}}" stepKey="startEditAttrSet"/>
<fillField selector="{{AdminProductFormSection.attributeSetFilter}}" userInput="{{ProductAttributeFrontendLabelTwo.label}}" stepKey="searchForAttrSet"/>
<click selector="{{AdminProductFormSection.attributeSetFilterResultByName(ProductAttributeFrontendLabelTwo.label)}}" stepKey="selectAttrSet"/>
<actionGroup ref="AdminSelectAttributeSetOnEditProductPageActionGroup" stepKey="startEditAttrSet">
<argument name="attributeSet" value="{{ProductAttributeFrontendLabelTwo.label}}"/>
</actionGroup>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="searchForAttrSet"/>
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="selectAttrSet"/>

<!--Product name and SKU-->
<fillField selector="{{AdminProductFormBundleSection.productName}}" userInput="{{BundleProduct.name2}}" stepKey="fillProductName"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<click selector="{{StorefrontHeaderSection.NavigationCategoryByName($$createCategory.name$$)}}" stepKey="cartClickCategory"/>

<!--Click add to cart-->
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverProduct"/>
<actionGroup ref="StorefrontHoverProductOnCategoryPageActionGroup" stepKey="hoverProduct"/>
<actionGroup ref="StorefrontClickAddToCartButtonActionGroup" stepKey="addProductToCart"/>

<!--Check for details page-->
Expand Down
8 changes: 7 additions & 1 deletion app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Model\ResourceModel\BundleFactory;
use Magento\Bundle\Model\ResourceModel\Option\Collection;
use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor;
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
use Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory;
use Magento\Bundle\Model\Selection;
Expand All @@ -28,6 +27,7 @@
use Magento\CatalogInventory\Api\StockStateInterface;
use Magento\CatalogInventory\Model\StockRegistry;
use Magento\CatalogInventory\Model\StockState;
use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor;
use Magento\Framework\DataObject;
use Magento\Framework\EntityManager\EntityMetadataInterface;
use Magento\Framework\EntityManager\MetadataPool;
Expand Down Expand Up @@ -1548,6 +1548,10 @@ public function testPrepareForCartAdvancedSpecifyProductOptions()
->disableOriginalConstructor()
->getMock();

$buyRequest->method('getOptions')
->willReturn([333 => ['type' => 'image/jpeg']]);
$option->method('getId')
->willReturn(333);
$this->parentClass($group, $option, $buyRequest, $product);

$product->expects($this->any())
Expand All @@ -1556,6 +1560,8 @@ public function testPrepareForCartAdvancedSpecifyProductOptions()
$buyRequest->expects($this->once())
->method('getBundleOption')
->willReturn([0, '', 'str']);
$group->expects($this->once())
->method('validateUserValue');

$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
$this->assertEquals('Please specify product option(s).', $result);
Expand Down
Loading

0 comments on commit 2561d07

Please sign in to comment.