Four51 / CustomSolutions

Custom Solutions
7 stars 15 forks source link

ProductMatrix - Restricted Pricing not Enforced #57

Open digitalalphas opened 6 years ago

digitalalphas commented 6 years ago

If a product is setup with Restricted price schedule, the user still sees an open textbox instead of a dropdown on the product page. A quick glance at the code, this solution appears to accommodate restricted price schedules but there is actually a bug preventing the dropdown to show and work correctly.

In order to get this working for a client, I switched "product.PriceSchedule" to "product.StandardPriceSchedule" in the template and added the function getRestrictedQtyText to the controller (modified version of quantityfield's function, to include the markup value in the results).

From: (template snippet - 2 specs) '<select id="451qa_input_qty" class="form-control" ng-change="qtyChanged()" ng-if="product.PriceSchedule.RestrictedQuantity" ng-model="item.Quantity" ng-options="pb.Quantity as getRestrictedQtyText(pb, product.QuantityMultiplier) for pb in product.PriceSchedule.PriceBreaks"><option value=""></option></select>', '<input id="451qa_input_qty" placeholder="0" autocomplete="off" class="form-control" ng-class="{\'qty-invalid\':item.QtyError}" ng-change="qtyChanged()" ng-if="!product.PriceSchedule.RestrictedQuantity" type="text" name="qtyInput" ng-model="item.Quantity"/>', (template snippet - 1 spec) '<select id="451qa_input_qty" class="form-control" ng-change="qtyChanged()" ng-if="product.PriceSchedule.RestrictedQuantity" ng-model="group[0].Quantity" ng-options="pb.Quantity as getRestrictedQtyText(pb, product.QuantityMultiplier) for pb in product.PriceSchedule.PriceBreaks"><option value=""></option></select>', '<input id="451qa_input_qty" placeholder="0" autocomplete="off" class="form-control" ng-class="{\'qty-invalid\':item.QtyError}" ng-change="qtyChanged()" ng-if="!product.PriceSchedule.RestrictedQuantity" type="text" name="qtyInput" ng-model="group[0].Quantity"/>',

To: (template snippet - 2 specs) '<select id="451qa_input_qty" class="form-control" ng-change="qtyChanged()" ng-if="product.StandardPriceSchedule.RestrictedQuantity" ng-model="item.Quantity" ng-options="pb.Quantity as getRestrictedQtyText(pb, product.QuantityMultiplier, item.Markup) for pb in product.StandardPriceSchedule.PriceBreaks"><option value=""></option></select>', '<input id="451qa_input_qty" placeholder="0" autocomplete="off" class="form-control" ng-class="{\'qty-invalid\':item.QtyError}" ng-change="qtyChanged()" ng-if="!product.StandardPriceSchedule.RestrictedQuantity" type="text" name="qtyInput" ng-model="item.Quantity"/>', (template snippet - 1 spec) '<select id="451qa_input_qty" class="form-control" ng-change="qtyChanged()" ng-if="product.StandardPriceSchedule.RestrictedQuantity" ng-model="group[0].Quantity" ng-options="pb.Quantity as getRestrictedQtyText(pb, product.QuantityMultiplier, group.Markup) for pb in product.StandardPriceSchedule.PriceBreaks"><option value=""></option></select>', '<input id="451qa_input_qty" placeholder="0" autocomplete="off" class="form-control" ng-class="{\'qty-invalid\':item.QtyError}" ng-change="qtyChanged()" ng-if="!product.StandardPriceSchedule.RestrictedQuantity" type="text" name="qtyInput" ng-model="group[0].Quantity"/>',

New function in ProductMatrixCtrl: $scope.getRestrictedQtyText = function(priceBreak, qtyMultiplier, markUp){ if(!markUp) markUp = 0; var qtyText = priceBreak.Quantity * qtyMultiplier; if(qtyMultiplier > 1) qtyText += ' - $' + Number((priceBreak.Price + markUp) * priceBreak.Quantity).toFixed(2); else qtyText += ' - $' + Number(qtyText * (priceBreak.Price + markUp)).toFixed(2); return qtyText; };