how to show the last item added to wishlist according to recent update date

We can show this by extending the view ProductListListDetailsView and under it we have to extend the child view ProductListListDetailsView and by using some more code, we can able to display the last updated item to show in the wishlist.

The updated date issue is now resolved, this has been done by changing the code which is in mini cart js file 
	_.extend(ProductListListDetailsView.prototype, {
					childViews: _.extend({}, ProductListListDetailsView.prototype.childViews, {
						'ProductList.ListDetails': function () {
							return new BackboneCollectionView({
								childView: ProductListListDetailsView,
								viewsPerRow: 1,
								collection: this.collection
							});
						}
					}),				
					
					getContext: _.wrap(ProductListListDetailsView.prototype.getContext, function (fn) {
						var context = fn.apply(this, _.toArray(arguments).slice(1));
						console.log('context', context);
						console.log('thissss', this)
						var itemList = this.options.model.get('items').models;
						console.log('itemList',itemList);
						var itemLength = context.itemsLength;
						var list = this.options.model;
						var items = list.get('items');
						var today = new Date(); // Get today's date
						var lastCreatedItem = _.max(items.models, function (item) {
							return new Date(item.get('created'));
						});
						const date = new Date();
						let day = date.getDate();
						let month = date.getMonth() + 1;
						let year = date.getFullYear();						
						// This arrangement can be altered based on how we want the date's format to appear.
						var currentDate = `${day}/${month}/${year}`;
						var [year1, month1, day1] = currentDate.split('/');
						currentDate = new Date(`${year1}-${month1}-${day1}`);
						console.log('currentDate',currentDate); 
						let nearestElement = null;
						let nearestDifference = Infinity;
						itemList.forEach(function(item) {
							console.log('item', item);
							var targetDate = item.get('createddate');
						    var [year, month, day] = targetDate.split('/');
							targetDate = new Date(`${year}-${month}-${day}`);
							console.log('targetDate',targetDate);
							const difference = Math.abs(currentDate - targetDate);
							console.log('difference',difference);
							if (difference < nearestDifference) {
								nearestElement = item;
								nearestDifference = difference;
							}							
						});
						console.log('nearestElement', nearestElement);
						context.lastModifiedDate =!!nearestElement?nearestElement.get('createddate'):list.get('lastmodifieddate');
						console.log('contextiiii', context);
					    context.lastItemDisplayName = nearestElement.get('item').get('_name');
					return context;
				})

Leave a comment

Your email address will not be published. Required fields are marked *