Hide The Reorder Button Under Purchase History for Restricted items

Scenario:
Restrict a customer to purchase/reorder the items from the purchase history detail page if the item is not enabled for the customer subsidiary. For example, if the item is available only in AU, NZ, and USA, then it should be visible only for those domains. Remove from the other domains.


Solution: We can extend the Reorder button functionality and display the message “Item not available in this subsidiary” for the items that have the Available checkbox not checked in the item record.

Code:

//reorder button in purchase history page
_.extend(OrderHistoryItemActionsView.prototype, {
  template: jj_restrictitems_reorder_tpl,
  getContext: _.wrap(OrderHistoryItemActionsView.prototype.getContext, function(fn) {
    let originalRet = fn.apply(this, _.toArray(arguments).slice(1));
    var profile = ProfileModel.getInstance();
    var subsidiary = profile.get('subsidiary');
    var allowedSubsidiaries = {
      1: 'custitem141',
      17: 'custitem144',
      2: 'custitem150',
      8: 'custitem146',
      12: 'custitem148',
      11: 'custitem142'
    };
    originalRet.isItemAvailable = this.model.get('item').get(allowedSubsidiaries[subsidiary]);
    return originalRet
  })
});
//reorder button in purchase history page

Custom template:
{{#if showActions}}
{{#if isItemAvailable}}
	<a 
		class="order-history-item-actions-reorder my-account-custom-button" 
		data-action="add-to-cart" 
		data-line-id="{{lineId}}" 
		data-item-id="{{itemId}}" 
		data-item-quantity="{{line.quantity}}"
		data-partial-quantity="{{line.partial_quantity}}" 
		data-parent-id="{{itemParentId}}" 
		data-item-options="{{lineFormatOptions}}">
		{{translate 'Reorder'}}
	</a>
	{{else}}
	<p>item is not available in this subsidairy</p>
	{{/if}}
{{/if}}

Leave a comment

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