Skip to content

Last Ordered Items block - bad js code  #13157

Closed
@Eytham

Description

@Eytham

The left block Last Ordered Items is not showing properly the Add to cart button on the :
data-bind="css: {'no-display': !lastOrderedItems().isShowAddToCart}
Always returning false.
Target JS file is : Magento_Sales/web/js/view/last-ordered-items.js

Preconditions

  1. Environnement Docker NGINX php 7
  2. Magento 2.2

Steps to reproduce

  1. In my account or in catalog, left block Last ordered items not showing properly for add to cart button

Expected result

  1. Add to cart button viewable to add last ordered items to cart

Actual result

  1. lastOrderedItems().isShowAddToCart always returning FALSE so the add to cart div actions stands with no-display CSS class

Original Code of Magento_Sales/web/js/view/last-ordered-items.js

define([
    'uiComponent',
    'Magento_Customer/js/customer-data'
], function (Component, customerData) {
    'use strict';

    return Component.extend({
        /** @inheritdoc */
        initialize: function () {
            var isShowAddToCart = false,
                item;

            this._super();
            this.lastOrderedItems = customerData.get('last-ordered-items');
            
            for (item in this.lastOrderedItems.items) {
                if (item['is_saleable']) {
                    isShowAddToCart = true;
                    break;
                }
            }

            this.lastOrderedItems.isShowAddToCart = isShowAddToCart;
        }
    });
});

My correction Code :

define([
    'uiComponent',
    'Magento_Customer/js/customer-data',
    'jquery'
], function (Component, customerData, $) {
    'use strict';

    return Component.extend({
        /** @inheritdoc */
        initialize: function () {
            var isShowAddToCart = false,
                item;
            
            this._super();
            this.lastOrderedItems = customerData.get('last-ordered-items');
            
            var self = this;
            $(this.lastOrderedItems().items).each(function(){
                if(this['is_saleable']) {
                    self.lastOrderedItems().isShowAddToCart = true;
                }
            });
        }
    });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions