Closed thdoan closed 7 years ago
@thdoan Thanks for reporting the issue. Do you use FPC?
@tkacheva No, all caches disabled in developer mode.
@thdoan thank you for your feedback, Please, recheck it on the latest 2.1 version of Magento. Since we have internal issue MAGETWO-56062 (Recently Viewed Products block does not appear when FPC is enabled) to check this case, please, disable FPC (System - Cache Management - Page Cache - Disabled)
I can still reproduce this issue in Magento 2.1.2.
My FPC is disabled and I'm in developer mode, and I also execute magento cache:clean
before reloading the page. My issue is not "Recently Viewed Products block does not appear when FPC is enabled" because I can still see simple products show up in the Recently Viewed Products block -- it is only configurable products that don't show up.
Are you saying you can see Caesar Warm-Up Pant in the Recently Viewed Products block on your system?
@thdoan Thanks for reporting the issue. Do you use sample data? Can you check manually created configurable product?
@slopukhov Yes we use sample data. Sorry, the production store does not have configurable products, so you'll have to reproduce using the sample data.
@thdoan Please describe what kind of a widget and through which section you add it. Since I use the following settings and I can not reproduce this issue on latest Magento 2.1 with latest Sample Data 2.1
@slopukhov I didn't add the widget through Admin -- I'm directly adding it in layout XML. Here are my two overrides (please try them also):
app/design/frontend/Vendor/theme/Magento_Theme/layout/catalog_product_view.xml
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content.aside">
<block class="Magento\Reports\Block\Product\Widget\Viewed" name="products.recent" template="widget/viewed/content/viewed_grid.phtml" after="-">
<arguments>
<argument name="page_size" xsi:type="string">10</argument><!-- Maximum number of items in the carousel -->
</arguments>
</block>
</referenceContainer>
</body>
</page>
app/design/frontend/Vendor/theme/Magento_Reports/templates/widget/viewed/content/viewed_grid.phtml
<?php
if ($exist = ($block->getRecentlyViewedProducts() && $block->getRecentlyViewedProducts()->getSize())) {
$type = 'widget-viewed';
$mode = 'grid';
$type = $type . '-' . $mode;
$image = 'recently_viewed_products_grid_content_widget';
$title = __('Recently Viewed');
$items = $block->getRecentlyViewedProducts();
$showWishlist = false;
$showCompare = false;
$showCart = false;
$rating = 'short';
$description = false;
}
?>
<?php if ($exist): ?>
<div class="block container-padded widget block-viewed-products-<?php echo $mode; ?>">
<div class="block-title title">
<h3 role="heading" aria-level="2"><?php echo $title; ?></h3>
</div>
<div class="block-content">
<?php echo '<!-- ' . $image . '-->' ?>
<div class="products-<?php echo $mode; ?> <?php echo $mode; ?> products-recent controls-outside">
<ol class="product-items <?php echo $type; ?> loading">
<?php $iterator = 1; ?>
<?php foreach ($items as $_item): ?>
<?php echo($iterator++ == 1) ? '<li class="product-item">' : '</li><li class="product-item">' ?>
<div class="product-item-info">
<a href="<?php echo $block->getProductUrl($_item) ?>" class="product-item-photo">
<?php echo $block->getImage($_item, $image)->toHtml(); ?>
</a>
<div class="product-item-details">
<strong class="product-item-name">
<a title="<?php echo $block->escapeHtml($_item->getName()) ?>"
href="<?php echo $block->getProductUrl($_item) ?>" class="product-item-link">
<?php echo $block->escapeHtml($_item->getName()) ?>
</a>
</strong>
<?php echo $block->getProductPriceHtml(
$_item,
\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
\Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
[
'price_id_suffix' => '-' . $type
]
) ?>
<?php if ($rating): ?>
<?php echo $block->getReviewsSummaryHtml($_item, $rating) ?>
<?php endif; ?>
<?php if ($showWishlist || $showCompare || $showCart): ?>
<div class="product-item-actions">
<?php if ($showCart): ?>
<div class="actions-primary">
<?php if ($_item->isSaleable()): ?>
<?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)): ?>
<button class="action tocart primary"
data-mage-init='{"redirectUrl": {"url": "<?php echo $block->getAddToCartUrl($_item) ?>"}}'
type="button" title="<?php echo __('Add to Cart') ?>">
<span><?php echo __('Add to Cart') ?></span>
</button>
<?php else: ?>
<?php
$postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
?>
<button class="action tocart primary"
data-post='<?php echo $postData; ?>'
type="button" title="<?php echo __('Add to Cart') ?>">
<span><?php echo __('Add to Cart') ?></span>
</button>
<?php endif; ?>
<?php else: ?>
<?php if ($_item->getIsSalable()): ?>
<div class="stock available"><span><?php echo __('In stock') ?></span></div>
<?php else: ?>
<div class="stock unavailable"><span><?php echo __('Out of stock') ?></span></div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($showWishlist || $showCompare): ?>
<div class="actions-secondary" data-role="add-to-links">
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && $showWishlist): ?>
<a href="#"
class="action towishlist" data-action="add-to-wishlist"
data-post='<?php echo $block->getAddToWishlistParams($_item); ?>'
title="<?php echo __('Add to Wish List') ?>">
<span><?php echo __('Add to Wish List') ?></span>
</a>
<?php endif; ?>
<?php if ($block->getAddToCompareUrl() && $showCompare): ?>
<?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare'); ?>
<a href="#" class="action tocompare"
data-post='<?php echo $compareHelper->getPostDataParams($_item); ?>'
title="<?php echo __('Add to Compare') ?>">
<span><?php echo __('Add to Compare') ?></span>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php echo($iterator == count($items)+1) ? '</li>' : '' ?>
<?php endforeach ?>
</ol>
</div>
<?php echo $block->getPagerHtml() ?>
</div>
</div>
<?php endif; ?>
With this code, the Recently Viewed widget is working fine for all products except configurable products, which for some reason are not displayed.
@thdoan I checked with your code and I do not have this problem. Could you recheck it on clean latest Magento 2.1 with latest sample data? Also, please, describe the configuration of your environment.
@slopukhov thanks for checking. Regarding my environment. I'm on Magento EE 2.1.2 in developer mode and I flush caches with the following commands before checking the page:
magento cache:clean
rm -rf /docroot/var/cache/* /docroot/var/generation/*
Is there anything more specific you want me to describe, such as Admin fields you want me to check or config/log files you want me to attach?
@thdoan Please describe the version of: OS, PHP, MySQL, Apache or Nginx. Also check the contents of the table - report_viewed_product_index.
OS = Linux (via Amazon Linux AMI 2016.09) PHP = v5.6.26 MySQL = v5.0.11 Server = Apache v20120211
report_viewed_product_index table:
+----------+------------+-------------+------------+----------+---------------------+
| index_id | visitor_id | customer_id | product_id | store_id | added_at |
+----------+------------+-------------+------------+----------+---------------------+
| 1558 | 460 | NULL | 18 | 1 | 2016-11-28 03:22:57 |
| 1559 | 461 | NULL | 18 | 1 | 2016-11-28 03:28:53 |
| 1561 | 461 | NULL | 1826 | 1 | 2016-11-28 03:46:06 |
| 1582 | 461 | NULL | 744 | 1 | 2016-11-28 07:04:39 |
| 1592 | 463 | NULL | 18 | 1 | 2016-11-28 11:15:40 |
| 1594 | 466 | NULL | 1826 | 1 | 2016-11-29 03:24:25 |
| 1595 | 467 | NULL | 1826 | 1 | 2016-11-29 03:31:08 |
| 1596 | 469 | NULL | 18 | 1 | 2016-11-29 04:30:32 |
| 1597 | 467 | NULL | 744 | 1 | 2016-11-29 07:50:35 |
| 1598 | 467 | NULL | 18 | 1 | 2016-11-29 07:50:49 |
+----------+------------+-------------+------------+----------+---------------------+
Three things to note:
$block->getRecentlyViewedProducts()->getSize()
returns 1
, so that's also working as expected<?php foreach ($items as $_item): ?>
loop never renders the <li>
for the configurable product (Caesar Warm-Up Pant) even though $block->getRecentlyViewedProducts()->getSize()
returns 1
, so this tells me something is not right about the $items = $block->getRecentlyViewedProducts()
collection.When I go to a third product (karmen-yoga-pant.html), $block->getRecentlyViewedProducts()->getSize()
correctly returns 2
(Caesar Warm-Up Pant, Pursuit Lumaflex Tone Band). However, the widget just shows Pursuit Lumaflex Tone Band, which is strange since the collection size is 2. I verified by viewing the HTML output that the <ol>
only contains one <li>
.
@thdoan Do you use MySQL v5.0.11? If yes, maybe problem in MySQL since we have next environment requirements.
According to contributor guide, tickets without response for two weeks should be closed. If this issue still reproducible please feel free to create the new one: format new issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result and specify Magento version.
Preconditions
Steps to reproduce
Expected result
Actual result
$block->getRecentlyViewedProducts()->getSize()
returns1
, but the<?php foreach ($items as $_item): ?>
loop doesn't return any<li>
s. This only happens with configurable products -- simple products do show up in the widget as expected.