[IMP] website_sale_{comparison,wishlist}: disable quick add to cart

This commit handles the disabling of the add to cart button optionnally.

task-2382027
This commit is contained in:
Thibault Libioulle
2022-04-14 14:33:23 +02:00
parent 3880bee744
commit 1518cd6ef9
7 changed files with 73 additions and 13 deletions
@@ -27,7 +27,7 @@ Finally, the module comes with an option to display an attribute summary table i
'assets': {
'web.assets_frontend': [
'website_sale_comparison/static/src/scss/website_sale_comparison.scss',
'website_sale_comparison/static/src/js/website_sale_comparison.js',
'website_sale_comparison/static/src/js/**/*.js',
],
'web.assets_tests': [
'website_sale_comparison/static/tests/**/*',
@@ -0,0 +1,16 @@
/** @odoo-module **/
import { WebsiteSale } from 'website_sale.website_sale';
WebsiteSale.include({
/**
* Toggles the add to cart button depending on the possibility of the
* current combination.
*
* @override
*/
_toggleDisable: function ($parent, isCombinationPossible) {
this._super(...arguments);
$parent.find('a.a-submit').toggleClass('disabled', !isCombinationPossible);
},
});
@@ -313,9 +313,22 @@ publicWidget.registry.ProductComparison = publicWidget.Widget.extend(cartHandler
productTrackingInfo.quantity = 1;
$inputProduct.trigger('add_to_cart_event', [productTrackingInfo]);
}
return this.addToCart({product_id: productId, add_qty: 1});
return this.addToCart(this._getAddToCartParams(productId, $form));
}
},
/**
* Get the addToCart Params
*
* @param {number} productId
* @param {JQuery} $form
* @override
*/
_getAddToCartParams(productId, $form) {
return {
product_id: productId,
add_qty: 1,
};
}
});
return ProductComparison;
});
@@ -113,11 +113,11 @@
<span t-esc="combination_info['display_name']"></span><br/>
</a>
<span>
<span class="o_comparison_price">
<strong>Price:</strong>
<del t-attf-class="text-danger mr8 {{'' if combination_info['has_discounted_price'] else 'd-none'}}" style="white-space: nowrap;" t-esc="combination_info['list_price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}" />
<span t-esc="combination_info['price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"></span>
<small class="d-block text-muted" groups="website_sale.group_show_uom_price" t-if="product.base_unit_price">
<small class="d-block text-muted" groups="website_sale.group_show_uom_price" t-if="combination_info['base_unit_price']">
<t t-call='website_sale.base_unit_price'/>
</small>
</span>
@@ -0,0 +1,16 @@
/** @odoo-module **/
import { WebsiteSale } from 'website_sale.website_sale';
WebsiteSale.include({
/**
* Toggles the add to cart button depending on the possibility of the
* current combination.
*
* @override
*/
_toggleDisable: function ($parent, isCombinationPossible) {
this._super(...arguments);
$parent.find('button.o_wish_add').toggleClass('disabled', !isCombinationPossible);
},
});
@@ -182,11 +182,7 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin,
}
return this._rpc({
route: "/shop/cart/update_json",
params: {
product_id: parseInt(productID, 10),
add_qty: parseInt(qty, 10),
display: false,
},
params: this._getCartUpdateJsonParams(productID, qty),
}).then(function (resp) {
if (resp.warning) {
if (! $('#data_warning').length) {
@@ -198,6 +194,19 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin,
$('.my_cart_quantity').html(resp.cart_quantity || '<i class="fa fa-warning" /> ');
});
},
/**
* Get the cart update params.
*
* @param {string} productId
* @param {string} qty
*/
_getCartUpdateJsonParams(productId, qty) {
return {
product_id: parseInt(productId, 10),
add_qty: parseInt(qty, 10),
display: false,
};
},
/**
* @private
*/
@@ -270,6 +279,10 @@ publicWidget.registry.ProductWishlist = publicWidget.Widget.extend(VariantMixin,
* @param {Event} ev
*/
_onClickWishAdd: function (ev) {
if (ev.currentTarget.classList.contains('disabled')) {
ev.preventDefault();
return;
}
var self = this;
this.$('.wishlist-section .o_wish_add').addClass('disabled');
this._addOrMoveWish(ev).then(function () {
@@ -171,20 +171,22 @@
<img t-attf-src="/web/image/product.product/#{wish.product_id.id}/image_128" class="img img-fluid" style="margin:auto;" alt="Product image"/>
</a>
</td>
<td class='text-left'>
<td class='text-left align-middle'>
<strong><a t-att-href="wish.product_id.website_url"><t t-esc="wish.product_id.display_name" /></a></strong>
<small class='d-none d-md-block'><p t-field="wish.product_id.description_sale" class="text-muted"/></small>
<button type="button" class="btn btn-link o_wish_rm no-decoration"><small><i class='fa fa-trash-o'></i> Remove</small></button>
</td>
<td class="align-middle">
<td class="align-middle o_wish_price">
<t t-esc="combination_info['price']" t-options="{'widget': 'monetary', 'display_currency': website.pricelist_id.currency_id}"/>
<small t-if="wish.product_id.base_unit_price" class="cart_product_base_unit_price d-block text-muted" groups="website_sale.group_show_uom_price">
<small t-if="combination_info['base_unit_price']" class="cart_product_base_unit_price d-block text-muted" groups="website_sale.group_show_uom_price">
<t t-call='website_sale.base_unit_price'><t t-set='product' t-value='wish.product_id' /></t>
</small>
</td>
<td class='text-center td-wish-btn align-middle'>
<input name="product_id" t-att-value="wish.product_id.id" type="hidden"/>
<button type="button" role="button" class="btn btn-secondary btn-block o_wish_add mb4" >Add <span class='d-none d-md-inline'>to Cart</span></button>
<button type="button" role="button" class="btn btn-secondary btn-block o_wish_add mb4" >
Add <span class='d-none d-md-inline'>to Cart</span>
</button>
</td>
</tr>
</t>