There's a couple of places where this was causing a cart update submission where it wasn't needed, eg the items had not actually changed. The conditional here was designed to stop that from happening, but it was actually passing every time (the conditional logic was not actually catching the case it was supposed to).
This is really expensive!
- Code is at a single place
- No need to import `localizeCurrencyFilter` into Controllers that required unit_prices
- Add `currencyconfig` into unit_prices_spec as it's now dependant to localizeCurrencyFilter
- Add method `processUnitPrice` which is responsible for computing the right unit price, that depends on `price`, `variant_unit_scale`, `variant_unit`, `unit_value` and `variant_unit_name`
- Watch the needed model to compute the unit price: `product.price` and `product.variant_unit_name`
- Add dependencies : UnitPrices and localizeCurrencyFilter
- Add currencyconfig to spec, as it's needed by localizeCurrencyFilter
- Put `'ng-controller' => 'unitsCtrl'` to the relevant node.
- Add new ng-model, as it's needed to watch it in order to compute unit price : `product.price`
- Finally display the needed information: `product.unit_price_value` and `product.unit_price_unit`
- Arguments were misordered and `scale` is needed to compute the denominator.
- Reorder "state machine" if-else as variant_unit_name is priority and "item" is too.
- @andrewpbrett I need your review here ;)
- Still need to test imperial system
Before if you did a bulk product update there was an error:
> TypeError: Cannot set property 'variants' of null
It only seemed to happen if pagination was required i.e. more than 15 products. It seemed to be happening because the default sort order on the products API endpoint which handles the bulk update is 'created desc' but 'name asc' on the /admin/products controller.
Another fix included here is for the sorting direction arrows which were not displaying on the admin products page. The sorting arrows require the sorting expression to be on the :sorting var instead of :q.sorting.
Fixes#6399
When the user entered a number beyond the stock level, the browser was
correcting that to the max number which is very helpful. But Angular was
setting the model to undefined which removes the item from the cart.
Deactivating Angular's max behaviour let's us set the value ourselves
which is then used in the cart.
If the user entered an invalid quantity, Angular set the model to
undefined and we removed the input field to show the add button. That
makes it impossible for a user to see what the maximum quantity to enter
would be. For example:
- The variant has a stock level of 5.
- The user enters 7.
- Angular sets it to undefined.
- The input field disappears.
- The user is startled and doesn't know how to proceed.
But now we hide the input only if it's deliberately set to zero.
The user can now type anything into the quantity field and some of it
may not be valid. These safe guards ensure that the buttons still work
even if the quantity is undefined or out of range.
Angular guards against the value being out of range but that has other
side-effects. We want to be able to de-activate some of Angular's
behaviour.