Skip to content

Commit ea71192

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.3-develop expedited
Accepted Community Pull Requests: - #24665: Refactor apply options of sales rule to it's own source model to simplify extending it (by @Bartlomiejsz) - #24634: fixed getting error in console while selecting all downloadable links #24633 (by @rani-webkul) - #24153: Fix config backend model PDF file name extension (by @Vinai) - #23767: #23766 - fix pattern validation on form submit (by @vahir2016) - #24030: 24025 add caching for magento product version (by @davidverholen) Fixed GitHub Issues: - #24633: Getting error in console while selecting all downloadable links (reported by @rani-webkul) has been fixed in #24634 by @rani-webkul in 2.3-develop branch Related commits: 1. 66b7785 - #24025: Slow Performance of ProductMetadata::getVersion (reported by @beberlei) has been fixed in #24030 by @davidverholen in 2.3-develop branch Related commits: 1. f0856e8 2. ed1fb03 3. b2ca7c8 4. b397814
2 parents bf6b166 + 32f8e29 commit ea71192

File tree

11 files changed

+288
-42
lines changed

11 files changed

+288
-42
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Config\Model\Config\Backend\File;
8+
9+
/**
10+
* System config PDF field backend model.
11+
*/
12+
class Pdf extends \Magento\Config\Model\Config\Backend\File
13+
{
14+
/**
15+
* @inheritdoc
16+
*/
17+
protected function _getAllowedExtensions()
18+
{
19+
return ['pdf'];
20+
}
21+
}

app/code/Magento/Config/Model/Config/Backend/Image/Pdf.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* System config image field backend model for Zend PDF generator
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
11-
*/
127
namespace Magento\Config\Model\Config\Backend\Image;
138

149
/**
10+
* System config PDF field backend model.
11+
*
1512
* @api
1613
* @since 100.0.2
14+
* @see \Magento\Config\Model\Config\Backend\File\Pdf
1715
*/
1816
class Pdf extends \Magento\Config\Model\Config\Backend\Image
1917
{
2018
/**
19+
* Returns the list of allowed file extensions.
20+
*
2121
* @return string[]
2222
*/
2323
protected function _getAllowedExtensions()
2424
{
25-
return ['tif', 'tiff', 'png', 'jpg', 'jpe', 'jpeg'];
25+
return ['tif', 'tiff', 'png', 'jpg', 'jpe', 'jpeg', 'pdf'];
2626
}
2727
}

app/code/Magento/Downloadable/Test/Mftf/Section/StorefrontDownloadableProductSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<element name="downloadableLinkByTitle" type="input" selector="//*[@id='downloadable-links-list']/*[contains(.,'{{title}}')]//input" parameterized="true" timeout="30"/>
1515
<element name="downloadableLinkSampleByTitle" type="text" selector="//label[contains(., '{{title}}')]/a[contains(@class, 'sample link')]" parameterized="true"/>
1616
<element name="downloadableSampleLabel" type="text" selector="//a[contains(.,normalize-space('{{title}}'))]" parameterized="true" timeout="30"/>
17+
<element name="downloadableLinkSelectAllCheckbox" type="checkbox" selector="#links_all" />
1718
</section>
1819
</sections>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="SelectAllDownloadableLinksDownloadableProductTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Create Downloadable Product"/>
15+
<title value="Select all downloadable links downloadable product test"/>
16+
<description value="All the downloadable links must be selected or unselected when anyone click on select all or unselect all checkbox respectively."/>
17+
<severity value="MAJOR"/>
18+
<group value="Downloadable"/>
19+
</annotations>
20+
<before>
21+
<!-- Create category -->
22+
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
23+
24+
<!-- Login as admin -->
25+
<actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/>
26+
27+
<!-- Create downloadable product -->
28+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="amOnProductGridPage"/>
29+
<waitForPageLoad stepKey="waitForProductGridPageLoad"/>
30+
<actionGroup ref="GoToSpecifiedCreateProductPage" stepKey="createProduct">
31+
<argument name="productType" value="downloadable"/>
32+
</actionGroup>
33+
34+
<!-- Fill downloadable product values -->
35+
<actionGroup ref="fillMainProductFormNoWeight" stepKey="fillDownloadableProductForm">
36+
<argument name="product" value="DownloadableProduct"/>
37+
</actionGroup>
38+
39+
<!-- Add downloadable product to category -->
40+
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}"
41+
parameterArray="[$$createCategory.name$$]" stepKey="fillCategory"/>
42+
43+
<!-- Fill downloadable link information before the creation link -->
44+
<actionGroup ref="AdminAddDownloadableLinkInformationActionGroup" stepKey="addDownloadableLinkInformation"/>
45+
46+
<!-- Links can be purchased separately -->
47+
<checkOption selector="{{AdminProductDownloadableSection.isLinksPurchasedSeparately}}"
48+
stepKey="checkOptionPurchaseSeparately"/>
49+
50+
<!-- Add first downloadable link -->
51+
<actionGroup ref="addDownloadableProductLinkWithMaxDownloads" stepKey="addFirstDownloadableProductLink">
52+
<argument name="link" value="downloadableLinkWithMaxDownloads"/>
53+
</actionGroup>
54+
55+
<!-- Add second downloadable link -->
56+
<actionGroup ref="addDownloadableProductLink" stepKey="addSecondDownloadableProductLink">
57+
<argument name="link" value="downloadableLink"/>
58+
</actionGroup>
59+
60+
<!-- Save product -->
61+
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
62+
</before>
63+
<after>
64+
<!-- Delete category -->
65+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
66+
67+
<!-- Delete created downloadable product -->
68+
<actionGroup ref="deleteProductUsingProductGrid" stepKey="deleteProduct">
69+
<argument name="product" value="DownloadableProduct"/>
70+
</actionGroup>
71+
72+
<!-- Log out -->
73+
<actionGroup ref="logout" stepKey="logout"/>
74+
</after>
75+
76+
<!-- Step 1: Navigate to store front Product page as guest -->
77+
<amOnPage url="/{{DownloadableProduct.sku}}.html"
78+
stepKey="amOnStorefrontProductPage"/>
79+
80+
<!-- Step 2: click on select all checkbox -->
81+
<click
82+
selector="{{StorefrontDownloadableProductSection.downloadableLinkSelectAllCheckbox}}"
83+
stepKey="selectAllProductLink"/>
84+
85+
<!-- Step 3: Make sure that all product links are checked -->
86+
<seeCheckboxIsChecked selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLinkWithMaxDownloads.title)}}" stepKey="seeFirstCheckboxChecked"/>
87+
88+
<seeCheckboxIsChecked selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLink.title)}}" stepKey="seeSecondCheckboxChecked"/>
89+
90+
<!-- Step 4: click again on select all checkbox -->
91+
<click
92+
selector="{{StorefrontDownloadableProductSection.downloadableLinkSelectAllCheckbox}}"
93+
stepKey="unselectAllProductLink"/>
94+
95+
<!-- Step 5: Make sure that all product links are unchecked -->
96+
<dontSeeCheckboxIsChecked selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLinkWithMaxDownloads.title)}}" stepKey="seeFirstCheckboxUnChecked"/>
97+
98+
<dontSeeCheckboxIsChecked selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLink.title)}}" stepKey="seeSecondCheckboxUnChecked"/>
99+
100+
</test>
101+
</tests>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Model\Rule\Action;
9+
10+
use Magento\Framework\Data\OptionSourceInterface;
11+
use Magento\SalesRule\Model\Rule;
12+
13+
/**
14+
* Class SimpleActionOptionsProvider
15+
*/
16+
class SimpleActionOptionsProvider implements OptionSourceInterface
17+
{
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function toOptionArray()
22+
{
23+
return [
24+
['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION],
25+
['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION],
26+
['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION],
27+
['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]
28+
];
29+
}
30+
}

app/code/Magento/SalesRule/Model/Rule/Metadata/ValueProvider.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
*/
66
namespace Magento\SalesRule\Model\Rule\Metadata;
77

8-
use Magento\SalesRule\Model\Rule;
9-
use Magento\Store\Model\System\Store;
108
use Magento\Customer\Api\GroupRepositoryInterface;
119
use Magento\Framework\Api\SearchCriteriaBuilder;
10+
use Magento\Framework\App\ObjectManager;
1211
use Magento\Framework\Convert\DataObject;
12+
use Magento\SalesRule\Model\Rule;
13+
use Magento\SalesRule\Model\Rule\Action\SimpleActionOptionsProvider;
14+
use Magento\SalesRule\Model\RuleFactory;
15+
use Magento\Store\Model\System\Store;
1316

1417
/**
1518
* Metadata provider for sales rule edit form.
@@ -37,31 +40,40 @@ class ValueProvider
3740
protected $objectConverter;
3841

3942
/**
40-
* @var \Magento\SalesRule\Model\RuleFactory
43+
* @var RuleFactory
4144
*/
4245
protected $salesRuleFactory;
4346

47+
/**
48+
* @var SimpleActionOptionsProvider
49+
*/
50+
private $simpleActionOptionsProvider;
51+
4452
/**
4553
* Initialize dependencies.
4654
*
4755
* @param Store $store
4856
* @param GroupRepositoryInterface $groupRepository
4957
* @param SearchCriteriaBuilder $searchCriteriaBuilder
5058
* @param DataObject $objectConverter
51-
* @param \Magento\SalesRule\Model\RuleFactory $salesRuleFactory
59+
* @param RuleFactory $salesRuleFactory
60+
* @param SimpleActionOptionsProvider|null $simpleActionOptionsProvider
5261
*/
5362
public function __construct(
5463
Store $store,
5564
GroupRepositoryInterface $groupRepository,
5665
SearchCriteriaBuilder $searchCriteriaBuilder,
5766
DataObject $objectConverter,
58-
\Magento\SalesRule\Model\RuleFactory $salesRuleFactory
67+
RuleFactory $salesRuleFactory,
68+
SimpleActionOptionsProvider $simpleActionOptionsProvider = null
5969
) {
6070
$this->store = $store;
6171
$this->groupRepository = $groupRepository;
6272
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
6373
$this->objectConverter = $objectConverter;
6474
$this->salesRuleFactory = $salesRuleFactory;
75+
$this->simpleActionOptionsProvider = $simpleActionOptionsProvider ?:
76+
ObjectManager::getInstance()->get(SimpleActionOptionsProvider::class);
6577
}
6678

6779
/**
@@ -71,15 +83,10 @@ public function __construct(
7183
* @return array
7284
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
7385
*/
74-
public function getMetadataValues(\Magento\SalesRule\Model\Rule $rule)
86+
public function getMetadataValues(Rule $rule)
7587
{
7688
$customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
77-
$applyOptions = [
78-
['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION],
79-
['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION],
80-
['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION],
81-
['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]
82-
];
89+
$applyOptions = $this->simpleActionOptionsProvider->toOptionArray();
8390

8491
$couponTypesOptions = [];
8592
$couponTypes = $this->salesRuleFactory->create()->getCouponTypes();
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\SalesRule\Test\Unit\Model\Rule\Action;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\SalesRule\Model\Rule;
11+
use Magento\SalesRule\Model\Rule\Action\SimpleActionOptionsProvider;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* @covers Magento\SalesRule\Model\Rule\Action\SimpleActionOptionsProvider
17+
*/
18+
class SimpleActionOptionsProviderTest extends TestCase
19+
{
20+
/**
21+
* @var SimpleActionOptionsProvider|MockObject
22+
*/
23+
protected $model;
24+
25+
protected function setUp()
26+
{
27+
$objectManager = new ObjectManager($this);
28+
29+
$this->model = $objectManager->getObject(SimpleActionOptionsProvider::class);
30+
}
31+
32+
public function testToOptionArray()
33+
{
34+
$expected = [
35+
['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION],
36+
['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION],
37+
['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION],
38+
['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]
39+
];
40+
41+
$this->assertEquals($expected, $this->model->toOptionArray());
42+
}
43+
}

0 commit comments

Comments
 (0)