Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request scandipwa#4956 from neeeeecka/4955-product-item-re…
Browse files Browse the repository at this point in the history
…direct
  • Loading branch information
carinadues authored Jun 23, 2022
2 parents 711c40c + 3a7a7eb commit 3f60152
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
14 changes: 12 additions & 2 deletions packages/scandipwa/src/component/AddToCart/AddToCart.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class AddToCart extends PureComponent {
layout: LayoutType.isRequired
};

handleButtonClick = this.handleButtonClick.bind(this);

renderCartIcon() {
const { isIconEnabled } = this.props;

Expand All @@ -45,18 +47,26 @@ export class AddToCart extends PureComponent {
return <CartIcon />;
}

handleButtonClick(e) {
// Prevent container Link from triggering redirect
e.stopPropagation();
e.preventDefault();

const { addProductToCart } = this.props;
addProductToCart();
}

render() {
const {
mix,
addProductToCart,
layout,
isDisabled,
isAdding
} = this.props;

return (
<button
onClick={ addProductToCart }
onClick={ this.handleButtonClick }
block="Button AddToCart"
mix={ mix }
mods={ { layout } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,14 @@ export class AddToCartContainer extends PureComponent {
[PRODUCT_TYPE.grouped]: this.validateGroup.bind(this)
};

async addProductToCart(e) {
async addProductToCart() {
const { product, addToCart, updateSelectedValues } = this.props;
await updateSelectedValues();

if ((!product || Object.keys(product).length === 0) && !addToCart) {
return;
}

e.preventDefault();
e.stopPropagation();
this.setState({ isAdding: true });

if (!this.validate()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export class ProductCard extends Product {

className = 'ProductCard';

registerSharedElement = this.registerSharedElement.bind(this);
handleLinkClick = this.handleLinkClick.bind(this);

registerSharedElement() {
handleLinkClick() {
const { registerSharedElement, isPlp } = this.props;

if (!isPlp) {
Expand Down Expand Up @@ -232,7 +232,7 @@ export class ProductCard extends Product {
block="ProductCard"
elem="Link"
to={ linkTo }
onClick={ this.registerSharedElement }
onClick={ this.handleLinkClick }
mix={ mix }
>
{ children }
Expand All @@ -256,6 +256,7 @@ export class ProductCard extends Product {
|| (type === PRODUCT_TYPE.configurable
&& Object.values(this.getConfigurableAttributes()).some((value) => value.attribute_values.length === 0));
const configureCustomize = options.some(({ required = false }) => required);

const configureDownloadableLinks = PRODUCT_TYPE.downloadable && links_purchased_separately === 1;

return configureBundleAndGrouped || configureConfig || configureCustomize || configureDownloadableLinks;
Expand All @@ -268,15 +269,17 @@ export class ProductCard extends Product {
inStock
} = this.props;

if (inStock && this.requiresConfiguration()) {
const requiresConfiguration = this.requiresConfiguration();

if (inStock && requiresConfiguration) {
return (
<button
block="Button AddToCart"
mods={ { layout } }
onClick={ showSelectOptionsNotification }
>
{ __('Add to cart') }
</button>
<button
block="Button AddToCart"
mods={ { layout } }
onClick={ showSelectOptionsNotification }
>
{ __('Add to cart') }
</button>
);
}

Expand Down

0 comments on commit 3f60152

Please sign in to comment.