Hi George,
The pipeline would be the most efficient way to do what you're asking for, I'd recommend overriding the "PreAddToCart" action to do so. but since you're looking only for modifying the viewset then you'll have to write both C# and JS, we already populate the product history in "product.OrderHistory" but it does not contain any info about the variants, you can get this value using the browser's console like this: angular.element($0).controller().product.OrderHistory
But make sue to inspect any element of the details module first as $0 refers to the selected element within the inspector.
This is an example to achieve you business logic using angular.js only, you'll need to add this at the bottom of the _Layout.cshtml of the details module, in side @{ ... } is a c# code to retrieve a list of the selected variants by looping through the order history, then we'll pass this list to the angular controller model (vm) and use it while the user change the variants selection:
@{
var orderDetailVariants = new List<ICollection<RazorCart.Service.Data.ModelDataContext.OrderDetailVariant>>();
foreach (var history in Model.Product.OrderHistory)
{
var detailVariants = RazorCart.Service.Data.Repository.Instance.ListOrderDetailVariants(history.OrderID, history.OrderDetailID);
orderDetailVariants.Add(detailVariants);
}
}
<script type="text/javascript">
let container@(Dnn.ModuleContext.ModuleId) = angular.element(document.getElementById('rzcContainer_@(Dnn.ModuleContext.ModuleId)'));
container@(Dnn.ModuleContext.ModuleId).ready(function () {
var scope = container@(Dnn.ModuleContext.ModuleId).scope();
var vm = container@(Dnn.ModuleContext.ModuleId).controller();
vm.canPurchase = { Value: true, Message: '' };
vm.orderDetailVariants = JSON.parse('@Html.Raw(Json.Encode(orderDetailVariants))');
scope.$watchCollection(function () {
return vm.variantsData;
}, function (newValue, oldVal) {
vm.canPurchase.Value = true;
angular.forEach(vm.orderDetailVariants, function (list, index) {
var match = false;
angular.forEach(list, function (item, index) {
angular.forEach(newValue, function (value, name) {
var groupId, variantId;
try {
groupId = name.substr(6, name.length - 1);
variantId = JSON.parse(value);
}
catch (e) { }
if (!isNaN(groupId)) {
if (item.VariantGroupID == groupId) {
if (item.VariantID == variantId)
match = true;
else
match = false;
}
}
});
});
if (match) {
vm.canPurchase.Value = false;
vm.canPurchase.Message = 'You have already bought this item before!';
return true;
}
});
});
scope.$apply(function () { });
});
</script>
PS you still need to use vm.canPurchase in Index.cshtml to show/hide AddToCart button or display the message to the user, you can use ng-if or ng-hide/ng-show