Skip to content

Commit 3df6681

Browse files
authored
Merge pull request #2576 from magento-honey-badgers/MAGETWO-91440-unassigned-attribute-n-a
[honey] Bug Fixes
2 parents af84959 + d5ee97a commit 3df6681

File tree

11 files changed

+247
-56
lines changed

11 files changed

+247
-56
lines changed

app/code/Magento/Catalog/Block/Product/Compare/ListCompare.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,22 @@ public function getProductAttributeValue($product, $attribute)
213213
return (string)$value == '' ? __('No') : $value;
214214
}
215215

216+
/**
217+
* Check if any of the products has a value set for the attribute
218+
*
219+
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
220+
* @return bool
221+
*/
222+
public function hasAttributeValueForProducts($attribute)
223+
{
224+
foreach ($this->getItems() as $item) {
225+
if ($item->hasData($attribute->getAttributeCode())) {
226+
return true;
227+
}
228+
}
229+
return false;
230+
}
231+
216232
/**
217233
* Retrieve Print URL
218234
*

app/code/Magento/Catalog/view/frontend/templates/product/compare/list.phtml

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
/* @var $block \Magento\Catalog\Block\Product\Compare\ListCompare */
1010
?>
11-
<?php $_total = $block->getItems()->getSize() ?>
12-
<?php if ($_total): ?>
11+
<?php $total = $block->getItems()->getSize() ?>
12+
<?php if ($total): ?>
1313
<a href="#" class="action print hidden-print" title="<?= /* @escapeNotVerified */ __('Print This Page') ?>">
1414
<span><?= /* @escapeNotVerified */ __('Print This Page') ?></span>
1515
</a>
@@ -24,14 +24,14 @@
2424
<caption class="table-caption"><?= /* @escapeNotVerified */ __('Compare Products') ?></caption>
2525
<thead>
2626
<tr>
27-
<?php $_i = 0 ?>
28-
<?php foreach ($block->getItems() as $_item): ?>
29-
<?php if ($_i++ == 0): ?>
27+
<?php $index = 0 ?>
28+
<?php foreach ($block->getItems() as $item): ?>
29+
<?php if ($index++ == 0): ?>
3030
<th scope="row" class="cell label remove"><span><?= /* @escapeNotVerified */ __('Remove Product') ?></span></th>
3131
<?php endif; ?>
3232
<td class="cell remove product hidden-print">
3333
<?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');?>
34-
<a href="#" data-post='<?= /* @escapeNotVerified */ $compareHelper->getPostDataRemove($_item) ?>'
34+
<a href="#" data-post='<?= /* @escapeNotVerified */ $compareHelper->getPostDataRemove($item) ?>'
3535
class="action delete" title="<?= /* @escapeNotVerified */ __('Remove Product') ?>">
3636
<span><?= /* @escapeNotVerified */ __('Remove Product') ?></span>
3737
</a>
@@ -41,35 +41,35 @@
4141
</thead>
4242
<tbody>
4343
<tr>
44-
<?php $_i = 0; ?>
45-
<?php $_helper = $this->helper('Magento\Catalog\Helper\Output'); ?>
46-
<?php /** @var $_item \Magento\Catalog\Model\Product */ ?>
47-
<?php foreach ($block->getItems() as $_item): ?>
48-
<?php if ($_i++ == 0): ?>
44+
<?php $index = 0; ?>
45+
<?php $helper = $this->helper('Magento\Catalog\Helper\Output'); ?>
46+
<?php /** @var $item \Magento\Catalog\Model\Product */ ?>
47+
<?php foreach ($block->getItems() as $item): ?>
48+
<?php if ($index++ == 0): ?>
4949
<th scope="row" class="cell label product"><span><?= /* @escapeNotVerified */ __('Product') ?></span></th>
5050
<?php endif; ?>
5151
<td data-th="<?= $block->escapeHtml(__('Product')) ?>" class="cell product info">
52-
<a class="product-item-photo" href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" title="<?= /* @escapeNotVerified */ $block->stripTags($_item->getName(), null, true) ?>">
53-
<?= $block->getImage($_item, 'product_comparison_list')->toHtml() ?>
52+
<a class="product-item-photo" href="<?= /* @escapeNotVerified */ $block->getProductUrl($item) ?>" title="<?= /* @escapeNotVerified */ $block->stripTags($item->getName(), null, true) ?>">
53+
<?= $block->getImage($item, 'product_comparison_list')->toHtml() ?>
5454
</a>
5555
<strong class="product-item-name">
56-
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" title="<?= /* @escapeNotVerified */ $block->stripTags($_item->getName(), null, true) ?>">
57-
<?= /* @escapeNotVerified */ $_helper->productAttribute($_item, $_item->getName(), 'name') ?>
56+
<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($item) ?>" title="<?= /* @escapeNotVerified */ $block->stripTags($item->getName(), null, true) ?>">
57+
<?= /* @escapeNotVerified */ $helper->productAttribute($item, $item->getName(), 'name') ?>
5858
</a>
5959
</strong>
60-
<?= $block->getReviewsSummaryHtml($_item, 'short') ?>
61-
<?= /* @escapeNotVerified */ $block->getProductPrice($_item, '-compare-list-top') ?>
60+
<?= $block->getReviewsSummaryHtml($item, 'short') ?>
61+
<?= /* @escapeNotVerified */ $block->getProductPrice($item, '-compare-list-top') ?>
6262
<div class="product-item-actions hidden-print">
6363
<div class="actions-primary">
64-
<?php if ($_item->isSaleable()): ?>
65-
<form data-role="tocart-form" action="<?= /* @escapeNotVerified */ $this->helper('Magento\Catalog\Helper\Product\Compare')->getAddToCartUrl($_item) ?>" method="post">
64+
<?php if ($item->isSaleable()): ?>
65+
<form data-role="tocart-form" action="<?= /* @escapeNotVerified */ $this->helper('Magento\Catalog\Helper\Product\Compare')->getAddToCartUrl($item) ?>" method="post">
6666
<?= $block->getBlockHtml('formkey') ?>
6767
<button type="submit" class="action tocart primary">
6868
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
6969
</button>
7070
</form>
7171
<?php else: ?>
72-
<?php if ($_item->getIsSalable()): ?>
72+
<?php if ($item->getIsSalable()): ?>
7373
<div class="stock available"><span><?= /* @escapeNotVerified */ __('In stock') ?></span></div>
7474
<?php else: ?>
7575
<div class="stock unavailable"><span><?= /* @escapeNotVerified */ __('Out of stock') ?></span></div>
@@ -78,7 +78,7 @@
7878
</div>
7979
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()) : ?>
8080
<div class="secondary-addto-links actions-secondary" data-role="add-to-links">
81-
<a href="#" data-post='<?= /* @escapeNotVerified */ $block->getAddToWishlistParams($_item) ?>' class="action towishlist" data-action="add-to-wishlist">
81+
<a href="#" data-post='<?= /* @escapeNotVerified */ $block->getAddToWishlistParams($item) ?>' class="action towishlist" data-action="add-to-wishlist">
8282
<span><?= /* @escapeNotVerified */ __('Add to Wish List') ?></span>
8383
</a>
8484
</div>
@@ -89,39 +89,41 @@
8989
</tr>
9090
</tbody>
9191
<tbody>
92-
<?php foreach ($block->getAttributes() as $_attribute): ?>
93-
<tr>
94-
<?php $_i = 0 ?>
95-
<?php foreach ($block->getItems() as $_item): ?>
96-
<?php if ($_i++ == 0): ?>
97-
<th scope="row" class="cell label">
98-
<span class="attribute label">
99-
<?= $block->escapeHtml($_attribute->getStoreLabel() ? $_attribute->getStoreLabel() : __($_attribute->getFrontendLabel())) ?>
100-
</span>
101-
</th>
102-
<?php endif; ?>
103-
<td class="cell product attribute">
104-
<div class="attribute value">
105-
<?php switch ($_attribute->getAttributeCode()) {
106-
case "price": ?>
107-
<?php
108-
/* @escapeNotVerified */ echo $block->getProductPrice(
109-
$_item,
110-
'-compare-list-' . $_attribute->getCode()
111-
)
112-
?>
113-
<?php break;
114-
case "small_image": ?>
115-
<?php $block->getImage($_item, 'product_small_image')->toHtml(); ?>
92+
<?php foreach ($block->getAttributes() as $attribute): ?>
93+
<?php $index = 0; ?>
94+
<?php if ($block->hasAttributeValueForProducts($attribute)): ?>
95+
<tr>
96+
<?php foreach ($block->getItems() as $item): ?>
97+
<?php if ($index++ == 0): ?>
98+
<th scope="row" class="cell label">
99+
<span class="attribute label">
100+
<?= $block->escapeHtml($attribute->getStoreLabel() ? $attribute->getStoreLabel() : __($attribute->getFrontendLabel())) ?>
101+
</span>
102+
</th>
103+
<?php endif; ?>
104+
<td class="cell product attribute">
105+
<div class="attribute value">
106+
<?php switch ($attribute->getAttributeCode()) {
107+
case "price": ?>
108+
<?php
109+
/* @escapeNotVerified */ echo $block->getProductPrice(
110+
$item,
111+
'-compare-list-' . $attribute->getCode()
112+
)
113+
?>
114+
<?php break;
115+
case "small_image": ?>
116+
<?php $block->getImage($item, 'product_small_image')->toHtml(); ?>
117+
<?php break;
118+
default: ?>
119+
<?= /* @escapeNotVerified */ $helper->productAttribute($item, $block->getProductAttributeValue($item, $attribute), $attribute->getAttributeCode()) ?>
116120
<?php break;
117-
default: ?>
118-
<?= /* @escapeNotVerified */ $_helper->productAttribute($_item, $block->getProductAttributeValue($_item, $_attribute), $_attribute->getAttributeCode()) ?>
119-
<?php break;
120-
} ?>
121-
</div>
122-
</td>
123-
<?php endforeach; ?>
124-
</tr>
121+
} ?>
122+
</div>
123+
</td>
124+
<?php endforeach; ?>
125+
</tr>
126+
<?php endif; ?>
125127
<?php endforeach; ?>
126128
</tbody>
127129
</table>

app/code/Magento/Ui/view/base/web/js/grid/filters/range.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ define([
2727
},
2828
date: {
2929
component: 'Magento_Ui/js/form/element/date',
30-
dateFormat: 'MM/dd/YYYY'
30+
dateFormat: 'MM/dd/YYYY',
31+
shiftedValue: 'filter'
3132
},
3233
text: {
3334
component: 'Magento_Ui/js/form/element/abstract'

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/ActionGroup/AdminProductGridActionGroup.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@
5353
<waitForElementNotVisible selector="{{AdminProductGridSection.loadingMask}}" stepKey="waitForFilteredGridLoad" time="30"/>
5454
</actionGroup>
5555

56+
<!--Filter the product grid by new from date filter-->
57+
<actionGroup name="filterProductGridBySetNewFromDate">
58+
<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFilters"/>
59+
<click selector="{{AdminProductGridFilterSection.filters}}" stepKey="openProductFilters"/>
60+
<fillField selector="{{AdminProductGridFilterSection.newFromDateFilter}}" userInput="05/16/2018" stepKey="fillSetAsNewProductFilter"/>
61+
<click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFilters"/>
62+
<waitForElementNotVisible selector="{{AdminProductGridSection.loadingMask}}" stepKey="waitForFilteredGridLoad" time="30"/>
63+
</actionGroup>
64+
5665
<!--Filter the product grid by a price range-->
5766
<actionGroup name="filterProductGridByPriceRange">
5867
<arguments>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Data/CustomAttributeData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@
3131
<data key="attribute_code">short_description</data>
3232
<data key="value" unique="suffix">API Product Short Description</data>
3333
</entity>
34+
<entity name="ApiProductNewsFromDate" type="custom_attribute">
35+
<data key="attribute_code">news_from_date</data>
36+
<data key="value">2018-05-17 00:00:00</data>
37+
</entity>
3438
</entities>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Data/ProductData.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,18 @@
267267
<requiredEntity type="custom_attribute_array">ApiProductDescription</requiredEntity>
268268
<requiredEntity type="custom_attribute_array">ApiProductShortDescription</requiredEntity>
269269
</entity>
270+
<entity name="SimpleProductWithNewFromDate" type="product">
271+
<data key="sku" unique="suffix">SimpleProduct</data>
272+
<data key="type_id">simple</data>
273+
<data key="attribute_set_id">4</data>
274+
<data key="name" unique="suffix">SimpleProduct</data>
275+
<data key="price">125.00</data>
276+
<data key="visibility">4</data>
277+
<data key="status">1</data>
278+
<data key="quantity">1000</data>
279+
<data key="urlKey" unique="suffix">simpleproduct</data>
280+
<data key="weight">1</data>
281+
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
282+
<requiredEntity type="custom_attribute_array">ApiProductNewsFromDate</requiredEntity>
283+
</entity>
270284
</entities>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductAttributeGridSection.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@
1111
<section name="AdminProductAttributeGridSection">
1212
<element name="AttributeCode" type="text" selector="//td[contains(text(),'{{var1}}')]" parameterized="true"/>
1313
<element name="createNewAttributeBtn" type="button" selector="button[data-index='add_new_attribute_button']"/>
14+
<element name="GridFilterFrontEndLabel" type="input" selector="#attributeGrid_filter_frontend_label"/>
15+
<element name="Search" type="button" selector="button[data-action=grid-filter-apply]" timeout="30"/>
16+
<element name="ResetFilter" type="button" selector="button[data-action='grid-filter-reset']" timeout="30"/>
17+
<element name="FirstRow" type="button" selector="//*[@id='attributeGrid_table']/tbody/tr[1]"/>
1418
</section>
1519
</sections>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductFormActionSection.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
<section name="AdminProductFormActionSection">
1212
<element name="backButton" type="button" selector="#back" timeout="30"/>
1313
<element name="saveButton" type="button" selector="#save-button" timeout="30"/>
14-
<element name="saveArrow" type="button" selector="button[data-ui-id='save-button-dropdown']" timeout="10"/>
15-
<element name="saveAndClose" type="button" selector="span[title='Save &amp; Close']" timeout="30"/>
14+
<element name="saveArrow" type="button" selector="button[data-ui-id='save-button-dropdown']" timeout="30"/>
15+
<!--<element name="saveAndClose" type="button" selector="span[title='Save &amp; Close']" timeout="30"/>-->
16+
<element name="saveAndClose" type="button" selector="span[id='save_and_close']" timeout="30"/>
1617
<element name="changeStoreButton" type="button" selector="#store-change-button" timeout="10"/>
1718
<element name="selectStoreView" type="button" selector="//ul[@data-role='stores-list']/li/a[normalize-space(.)='{{var1}}']" timeout="10" parameterized="true"/>
1819
</section>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminProductGridFilterSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<element name="priceFilterTo" type="input" selector="input.admin__control-text[name='price[to]']"/>
2929
<element name="typeFilter" type="select" selector="select.admin__control-select[name='type_id']"/>
3030
<element name="statusFilter" type="select" selector="select.admin__control-select[name='status']"/>
31+
<element name="newFromDateFilter" type="input" selector="input.admin__control-text[name='news_from_date[from]']"/>
3132
<element name="keywordSearch" type="input" selector="input#fulltext"/>
3233
<element name="keywordSearchButton" type="button" selector=".data-grid-search-control-wrap button.action-submit" timeout="30"/>
3334
</section>

0 commit comments

Comments
 (0)