Skip to content

Commit 5f3ef92

Browse files
committed
PB-107: Display total number of products matched into ProductsList
- populate total number of products
1 parent 94a09da commit 5f3ef92

File tree

9 files changed

+301
-57
lines changed

9 files changed

+301
-57
lines changed

app/code/Magento/PageBuilder/Controller/Adminhtml/Form/Element/ProductTotals.php

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

7+
declare(strict_types=1);
8+
79
namespace Magento\PageBuilder\Controller\Adminhtml\Form\Element;
810

9-
class ProductTotals extends \Magento\Backend\App\Action
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\Framework\App\Action\HttpPostActionInterface;
13+
14+
/**
15+
* Returns the number of products that match the provided conditions
16+
*/
17+
class ProductTotals extends \Magento\Backend\App\Action implements HttpPostActionInterface
1018
{
19+
const ADMIN_RESOURCE = 'Magento_Catalog::products';
20+
1121
/**
1222
* Product collection factory
1323
*
@@ -20,13 +30,6 @@ class ProductTotals extends \Magento\Backend\App\Action
2030
*/
2131
private $sqlBuilder;
2232

23-
/**
24-
* Catalog product visibility
25-
*
26-
* @var \Magento\Catalog\Model\Product\Visibility
27-
*/
28-
private $catalogProductVisibility;
29-
3033
/**
3134
* @var \Magento\CatalogWidget\Model\Rule
3235
*/
@@ -48,9 +51,10 @@ class ProductTotals extends \Magento\Backend\App\Action
4851
private $jsonFactory;
4952

5053
/**
54+
* Constructor.
55+
*
5156
* @param \Magento\Backend\App\Action\Context $context
5257
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
53-
* @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
5458
* @param \Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder
5559
* @param \Magento\CatalogWidget\Model\Rule $rule
5660
* @param \Magento\Widget\Helper\Conditions $conditionsHelper
@@ -60,15 +64,13 @@ class ProductTotals extends \Magento\Backend\App\Action
6064
public function __construct(
6165
\Magento\Backend\App\Action\Context $context,
6266
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
63-
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
6467
\Magento\Rule\Model\Condition\Sql\Builder $sqlBuilder,
6568
\Magento\CatalogWidget\Model\Rule $rule,
6669
\Magento\Widget\Helper\Conditions $conditionsHelper,
6770
\Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
6871
\Magento\Framework\Controller\Result\JsonFactory $jsonFactory
6972
) {
7073
$this->productCollectionFactory = $productCollectionFactory;
71-
$this->catalogProductVisibility = $catalogProductVisibility;
7274
$this->sqlBuilder = $sqlBuilder;
7375
$this->rule = $rule;
7476
$this->conditionsHelper = $conditionsHelper;
@@ -111,7 +113,6 @@ private function createCollection()
111113
{
112114
/** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
113115
$collection = $this->productCollectionFactory->create();
114-
$collection = $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
115116

116117
/** @var \Magento\Rule\Model\Condition\Combine $conditions */
117118
$conditions = $this->getConditions();
@@ -128,15 +129,24 @@ private function createCollection()
128129
}
129130

130131
/**
131-
* {@inheritdoc}
132+
* @inheritdoc
132133
*/
133134
public function execute()
134135
{
135136
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
136137
$collection = $this->createCollection();
138+
$totalProducts = $collection->load()->getSize();
139+
$disabledProducts = $collection
140+
->addAttributeToFilter('status', Status::STATUS_DISABLED)
141+
->load()
142+
->getSize();
143+
137144
return $this->jsonFactory->create()
138-
->setData([
139-
'total' => $collection->getSize()
140-
]);
145+
->setData(
146+
[
147+
'total' => $totalProducts,
148+
'disabled' => $disabledProducts
149+
]
150+
);
141151
}
142152
}

app/code/Magento/PageBuilder/Test/Mftf/ActionGroup/ContentTypeProductsActionGroup.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,12 @@
487487
<actualResult type="variable">differenceBetweenCenterPositions</actualResult>
488488
</assertLessThanOrEqual>
489489
</actionGroup>
490+
<actionGroup name="validateProductTotals">
491+
<arguments>
492+
<argument name="property"/>
493+
</arguments>
494+
<waitForPageLoad stepKey="waitForPageLoad"/>
495+
<waitForElement time="2" selector="{{EditPanelForm.panelFieldControl(property.section, property.fieldName)}}" stepKey="waitForElementVisible"/>
496+
<see selector="{{EditPanelForm.panelFieldControl(property.section, property.fieldName)}}" userInput="{{property.value}}" stepKey="seeProductTotals"/>
497+
</actionGroup>
490498
</actionGroups>

app/code/Magento/PageBuilder/Test/Mftf/Data/ProductsData.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,24 @@
162162
<data key="value"/>
163163
<data key="errorMessage">This is a required field.</data>
164164
</entity>
165+
<entity name="PageBuilderTotalProductsPropertyThree" type="pagebuilder_products_grid_total_products">
166+
<data key="name"></data>
167+
<data key="section">appearance_fieldset</data>
168+
<data key="fieldName">product_totals</data>
169+
<data key="value">of 3 (0 disabled)</data>
170+
</entity>
171+
<entity name="PageBuilderTotalProductsPropertyOne" type="pagebuilder_products_grid_total_products">
172+
<data key="name"></data>
173+
<data key="section">appearance_fieldset</data>
174+
<data key="fieldName">product_totals</data>
175+
<data key="value">of 1 (0 disabled)</data>
176+
</entity>
177+
<entity name="PageBuilderTotalProductsPropertyTwoOneDisabled" type="pagebuilder_products_grid_total_products">
178+
<data key="name"></data>
179+
<data key="section">appearance_fieldset</data>
180+
<data key="fieldName">product_totals</data>
181+
<data key="value">of 2 (1 disabled)</data>
182+
</entity>
165183
<!-- Number of Products to Display: Carousel Appearance -->
166184
<entity name="PageBuilderProductsCarouselCountPropertyOne" type="pagebuilder_products_carousel_number_of_products">
167185
<data key="name">Number of Products to Display</data>
@@ -233,6 +251,24 @@
233251
<data key="value"/>
234252
<data key="errorMessage">This is a required field.</data>
235253
</entity>
254+
<entity name="PageBuilderProductsCarouselTotalProductsPropertyThree" type="pagebuilder_products_grid_total_products">
255+
<data key="name"></data>
256+
<data key="section">appearance_fieldset</data>
257+
<data key="fieldName">carousel_product_totals</data>
258+
<data key="value">of 3 (0 disabled)</data>
259+
</entity>
260+
<entity name="PageBuilderProductsCarouselTotalProductsPropertyOne" type="pagebuilder_products_grid_total_products">
261+
<data key="name"></data>
262+
<data key="section">appearance_fieldset</data>
263+
<data key="fieldName">carousel_product_totals</data>
264+
<data key="value">of 1 (0 disabled)</data>
265+
</entity>
266+
<entity name="PageBuilderProductsCarouselTotalProductsPropertyTwoOneDisabled" type="pagebuilder_products_grid_total_products">
267+
<data key="name"></data>
268+
<data key="section">appearance_fieldset</data>
269+
<data key="fieldName">carousel_product_totals</data>
270+
<data key="value">of 2 (1 disabled)</data>
271+
</entity>
236272
<!-- Carousel Settings: Carousel Mode -->
237273
<entity name="PageBuilderProductsCarouselSettingsCarouselMode_Default" type="pagebuilder_products_carousel_mode">
238274
<data key="name">Autoplay</data>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminPageBuilderProductsCommonTests.xml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,4 +1098,145 @@
10981098
</actionGroup>
10991099
<dontSeeElementInDOM selector="{{ProductsOnStorefront.product('1')}}" stepKey="validateProductCountStorefrontAfterChangingToFalse"/>
11001100
</test>
1101+
<test name="AdminPageBuilderProductsConfigurationValidateProductTotals">
1102+
<annotations>
1103+
<features value="PageBuilder"/>
1104+
<stories value="Products"/>
1105+
<title value="Validate Product Totals"/>
1106+
<description value="Validate the total number of products shown for the selected conditions in the Advanced Configuration form and on Stage for Product List."/>
1107+
<severity value="CRITICAL"/>
1108+
<useCaseId value="PB-107"/>
1109+
<testCaseId value="MC-22882"/>
1110+
<group value="pagebuilder"/>
1111+
<group value="pagebuilder-products"/>
1112+
</annotations>
1113+
<before>
1114+
<createData entity="PageBuilderProductsSubCategory" stepKey="createPreReqCategory1"/>
1115+
<createData entity="PageBuilderProductsSubCategory" stepKey="createPreReqCategory2"/>
1116+
<createData entity="_defaultProduct" stepKey="createPreReqProduct1">
1117+
<requiredEntity createDataKey="createPreReqCategory1"/>
1118+
</createData>
1119+
<createData entity="_defaultProduct" stepKey="createPreReqProduct2">
1120+
<requiredEntity createDataKey="createPreReqCategory1"/>
1121+
</createData>
1122+
<createData entity="_defaultProduct" stepKey="createPreReqProduct3">
1123+
<requiredEntity createDataKey="createPreReqCategory1"/>
1124+
</createData>
1125+
<createData entity="_defaultProduct" stepKey="createPreReqProduct4">
1126+
<requiredEntity createDataKey="createPreReqCategory2"/>
1127+
</createData>
1128+
<createData entity="SimpleProductDisabled" stepKey="createPreReqProduct5">
1129+
</createData>
1130+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
1131+
<actionGroup ref="navigateToAPageWithPageBuilder" stepKey="navigateToAPageWithPageBuilder"/>
1132+
<actionGroup ref="switchToPageBuilderStage" stepKey="switchToPageBuilderStage"/>
1133+
</before>
1134+
<after>
1135+
<deleteData createDataKey="createPreReqProduct1" stepKey="deletePreReqProduct1"/>
1136+
<deleteData createDataKey="createPreReqProduct2" stepKey="deletePreReqProduct2"/>
1137+
<deleteData createDataKey="createPreReqProduct3" stepKey="deletePreReqProduct3"/>
1138+
<deleteData createDataKey="createPreReqProduct4" stepKey="deletePreReqProduct4"/>
1139+
<deleteData createDataKey="createPreReqProduct5" stepKey="deletePreReqProduct5"/>
1140+
<deleteData createDataKey="createPreReqCategory1" stepKey="deletePreReqCategory1"/>
1141+
<deleteData createDataKey="createPreReqCategory2" stepKey="deletePreReqCategory2"/>
1142+
<actionGroup ref="logout" stepKey="logout"/>
1143+
</after>
1144+
<actionGroup ref="addPageBuilderPageTitle" stepKey="enterPageTitle">
1145+
<argument name="contentType" value="PageBuilderProductsContentType"/>
1146+
</actionGroup>
1147+
<actionGroup ref="expandPageBuilderPanelMenuSection" stepKey="expandMenuSectionAddContent">
1148+
<argument name="contentType" value="PageBuilderProductsContentType"/>
1149+
</actionGroup>
1150+
<actionGroup ref="dragContentTypeToStage" stepKey="dragProductsIntoStage">
1151+
<argument name="contentType" value="PageBuilderProductsContentType"/>
1152+
</actionGroup>
1153+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterDrop">
1154+
<argument name="contentType" value="PageBuilderProductsContentType"/>
1155+
</actionGroup>
1156+
<!-- Select Products By Category -->
1157+
<actionGroup ref="chooseVisualSelectOption" stepKey="selectGridAppearanceForCategory">
1158+
<argument name="property" value="PageBuilderProductsProductGridAppearance"/>
1159+
</actionGroup>
1160+
<actionGroup ref="chooseVisualSelectOption" stepKey="chooseSelectProductsByCategory">
1161+
<argument name="property" value="PageBuilderProductsSelectProductsByCategory"/>
1162+
</actionGroup>
1163+
<actionGroup ref="selectCategoryFromCategoryDropDown" stepKey="selectCategory">
1164+
<argument name="category" value="$$createPreReqCategory1.name$$"/>
1165+
</actionGroup>
1166+
<!-- Verify Total Products by Category for Grid Appearance -->
1167+
<actionGroup ref="validateProductTotals" stepKey="validateTotalProductsForCategoryAndGrid">
1168+
<argument name="property" value="PageBuilderTotalProductsPropertyThree"/>
1169+
</actionGroup>
1170+
<actionGroup ref="saveEditPanelSettings" stepKey="saveValidationEditPanelSettings"/>
1171+
<!-- Validate Stage -->
1172+
<actionGroup ref="validateProductCountInProducts" stepKey="validateProductsCountStageForCategoryAndGrid">
1173+
<argument name="page" value="ProductsOnStage"/>
1174+
<argument name="count" value="3"/>
1175+
</actionGroup>
1176+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterVerifyingStageForCategoryAndGrid">
1177+
<argument name="contentType" value="PageBuilderProductsContentType"/>
1178+
</actionGroup>
1179+
<!-- Verify Total Products by Category for Carousel Appearance -->
1180+
<actionGroup ref="chooseVisualSelectOption" stepKey="selectCarouselAppearance">
1181+
<argument name="property" value="PageBuilderProductsProductCarouselAppearance"/>
1182+
</actionGroup>
1183+
<actionGroup ref="validateProductTotals" stepKey="validateTotalProductsForCategoryAndCarousel">
1184+
<argument name="property" value="PageBuilderProductsCarouselTotalProductsPropertyThree"/>
1185+
</actionGroup>
1186+
<!-- Select Products By Sku -->
1187+
<actionGroup ref="chooseVisualSelectOption" stepKey="chooseSelectProductsBySku">
1188+
<argument name="property" value="PageBuilderProductsSelectProductsBySKU"/>
1189+
</actionGroup>
1190+
<actionGroup ref="addSKUsToSelectProductsBySKU" stepKey="addProductsSKUsToInputField">
1191+
<argument name="SKUs" value="$$createPreReqProduct5.sku$$,$$createPreReqProduct1.sku$$"/>
1192+
</actionGroup>
1193+
<!-- Verify Total Products by Sku for Carousel Appearance -->
1194+
<actionGroup ref="validateProductTotals" stepKey="validateTotalProductsForSkusAndCarousel">
1195+
<argument name="property" value="PageBuilderProductsCarouselTotalProductsPropertyTwoOneDisabled"/>
1196+
</actionGroup>
1197+
<actionGroup ref="saveEditPanelSettings" stepKey="saveEditPanelSettingsForSkuAndCarousel"/>
1198+
<!-- Validate Stage -->
1199+
<actionGroup ref="validateProductCountInProducts" stepKey="validateProductsCountStageForSkuAndCarousel">
1200+
<argument name="page" value="ProductsCarouselOnStage"/>
1201+
<argument name="count" value="1"/>
1202+
</actionGroup>
1203+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterVerifyingStageForSkuAndCarousel">
1204+
<argument name="contentType" value="PageBuilderProductsContentType"/>
1205+
</actionGroup>
1206+
<!-- Verify Total Products by Sku for Grid Appearance -->
1207+
<actionGroup ref="chooseVisualSelectOption" stepKey="selectGridAppearanceForSku">
1208+
<argument name="property" value="PageBuilderProductsProductGridAppearance"/>
1209+
</actionGroup>
1210+
<actionGroup ref="validateProductTotals" stepKey="validateTotalProductsForSkuAndGrid">
1211+
<argument name="property" value="PageBuilderTotalProductsPropertyTwoOneDisabled"/>
1212+
</actionGroup>
1213+
<!-- Select Products By Condition -->
1214+
<actionGroup ref="chooseVisualSelectOption" stepKey="chooseSelectProductsByCondition">
1215+
<argument name="property" value="PageBuilderProductsSelectProductsByCondition"/>
1216+
</actionGroup>
1217+
<actionGroup ref="addConditionToProductConditions" stepKey="addCategoryCondition">
1218+
<argument name="conditionInput" value="$$createPreReqCategory2.id$$"/>
1219+
</actionGroup>
1220+
<click selector="{{ProductsContentTypeForm.conditionsListText}}" stepKey="clickOutOfConditionField"/>
1221+
<!-- Verify Total Products by Condition for Grid Appearance -->
1222+
<actionGroup ref="validateProductTotals" stepKey="validateTotalProductsForConditionAndGrid">
1223+
<argument name="property" value="PageBuilderTotalProductsPropertyOne"/>
1224+
</actionGroup>
1225+
<actionGroup ref="saveEditPanelSettings" stepKey="saveValidationEditPanelSettingsForConditionAndGrid"/>
1226+
<!-- Validate Stage -->
1227+
<actionGroup ref="validateProductCountInProducts" stepKey="validateProductsCountStageForConditionAndGrid">
1228+
<argument name="page" value="ProductsOnStage"/>
1229+
<argument name="count" value="1"/>
1230+
</actionGroup>
1231+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterVerifyingStageForConditionAndGrid">
1232+
<argument name="contentType" value="PageBuilderProductsContentType"/>
1233+
</actionGroup>
1234+
<!-- Verify Total Products by Condition for Carousel Appearance -->
1235+
<actionGroup ref="chooseVisualSelectOption" stepKey="selectCarouselAppearanceForCondition">
1236+
<argument name="property" value="PageBuilderProductsProductCarouselAppearance"/>
1237+
</actionGroup>
1238+
<actionGroup ref="validateProductTotals" stepKey="validateTotalProductsForConditionAndCarousel">
1239+
<argument name="property" value="PageBuilderProductsCarouselTotalProductsPropertyOne"/>
1240+
</actionGroup>
1241+
</test>
11011242
</tests>

0 commit comments

Comments
 (0)