Skip to content

Commit ba2918d

Browse files
cpapazogloucpap
andauthored
Marketplace: clean up and setup paid plugins purchase flow (#59065)
* Marketplace: removes productGroupSlug and static product references. * Marketplace: removes product definitions. * Marketplace: removes code and files not used anymore. * Marketplace: renames plugin upload status to plugin install. * Marketplace: fixes class names. * Marketplace: remove shopping cart from domain upsell. * Marketplace: disallow removing business bundle for carts containing marketplace products. * Marketplace Test: adds paid plugin flow to test page. * Marketplace: fixes selector arguement. * Marketplace: fixes lint problems. * Marketplace: removes jsdoc due to TS. * Rebase fixes. * Marketplace test: adds comment for monthly pricing * Rebase fixes. * Marketplace: disallow business plan removal for marketplace items. * Marketplace: fixes tests. * Marketplace: ignores test file for ts errors. * Marketplace: fixes theme provider ts errors. Co-authored-by: cpap <[email protected]>
1 parent c8471ef commit ba2918d

File tree

35 files changed

+68
-1782
lines changed

35 files changed

+68
-1782
lines changed

client/my-sites/checkout/checkout-thank-you/marketplace/marketplace-thank-you-YOAST.tsx

Lines changed: 0 additions & 165 deletions
This file was deleted.

client/my-sites/checkout/composite-checkout/components/wp-order-review-line-items.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isPremium } from '@automattic/calypso-products';
1+
import { isPremium, isBusiness } from '@automattic/calypso-products';
22
import { FormStatus, useFormStatus } from '@automattic/composite-checkout';
33
import {
44
getCouponLineItemFromCart,
@@ -11,7 +11,9 @@ import {
1111
import styled from '@emotion/styled';
1212
import PropTypes from 'prop-types';
1313
import * as React from 'react';
14+
import { useSelector } from 'react-redux';
1415
import { hasDIFMProduct } from 'calypso/lib/cart-values/cart-items';
16+
import { isMarketplaceProduct } from 'calypso/state/products-list/selectors';
1517
import { ItemVariationPicker } from './item-variation-picker';
1618
import type { OnChangeItemVariant } from './item-variation-picker';
1719
import type { Theme } from '@automattic/composite-checkout';
@@ -77,6 +79,11 @@ export function WPOrderReviewLineItems( {
7779
const couponLineItem = getCouponLineItemFromCart( responseCart );
7880
const { formStatus } = useFormStatus();
7981
const isDisabled = formStatus !== FormStatus.READY;
82+
const hasMarketplaceProduct = useSelector( ( state ) =>
83+
responseCart.products.some( ( product: ResponseCartProduct ) =>
84+
isMarketplaceProduct( state, product.product_slug )
85+
)
86+
);
8087

8188
return (
8289
<WPOrderReviewList className={ joinClasses( [ className, 'order-review-line-items' ] ) }>
@@ -90,7 +97,7 @@ export function WPOrderReviewLineItems( {
9097
<WPOrderReviewListItem key={ product.uuid }>
9198
<LineItem
9299
product={ product }
93-
hasDeleteButton={ canItemBeDeleted( product, responseCart ) }
100+
hasDeleteButton={ canItemBeDeleted( product, responseCart, hasMarketplaceProduct ) }
94101
removeProductFromCart={ removeProductFromCart }
95102
isSummary={ isSummary }
96103
createUserAndSiteBeforeTransaction={ createUserAndSiteBeforeTransaction }
@@ -149,23 +156,28 @@ WPOrderReviewLineItems.propTypes = {
149156

150157
/**
151158
* Checks if the given item is the premium plan product and the DIFM product exists in the provided shopping cart object
152-
*
153-
* @param item The shopping basket line item
154-
* @param cartProducts The shopping cart object
155-
* @returns boolean
156159
*/
157-
function isPremiumPlanWithDIFMInTheCart( item: ResponseCartProduct, cartProducts: ResponseCart ) {
158-
return isPremium( item ) && hasDIFMProduct( cartProducts );
160+
function isPremiumPlanWithDIFMInTheCart( item: ResponseCartProduct, responseCart: ResponseCart ) {
161+
return isPremium( item ) && hasDIFMProduct( responseCart );
159162
}
160163

161-
function canItemBeDeleted( item: ResponseCartProduct, cartProducts: ResponseCart ): boolean {
164+
function canItemBeDeleted(
165+
item: ResponseCartProduct,
166+
responseCart: ResponseCart,
167+
hasMarketplaceProduct: boolean
168+
): boolean {
162169
const itemTypesThatCannotBeDeleted = [ 'domain_redemption' ];
163170
if ( itemTypesThatCannotBeDeleted.includes( item.product_slug ) ) {
164171
return false;
165172
}
166173

167174
// The Premium plan cannot be removed from the cart when in combination with the DIFM lite product
168-
if ( isPremiumPlanWithDIFMInTheCart( item, cartProducts ) ) {
175+
if ( isPremiumPlanWithDIFMInTheCart( item, responseCart ) ) {
176+
return false;
177+
}
178+
179+
// The Business plan cannot be removed from the cart when in combination with a marketplace product
180+
if ( isBusiness( item ) && hasMarketplaceProduct ) {
169181
return false;
170182
}
171183
return true;

client/my-sites/checkout/composite-checkout/test/composite-checkout-variant-picker.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { render, fireEvent, screen, within } from '@testing-library/react';
77
import { Provider as ReduxProvider } from 'react-redux';
88
import '@testing-library/jest-dom/extend-expect';
99
import useCartKey from 'calypso/my-sites/checkout/use-cart-key';
10+
import { isMarketplaceProduct } from 'calypso/state/products-list/selectors';
1011
import { getDomainsBySiteId, hasLoadedSiteDomains } from 'calypso/state/sites/domains/selectors';
1112
import { getPlansBySiteId } from 'calypso/state/sites/plans/selectors/get-plans-by-site';
1213
import CompositeCheckout from '../composite-checkout';
@@ -32,6 +33,7 @@ jest.mock( 'calypso/state/selectors/is-site-automated-transfer' );
3233
jest.mock( 'calypso/state/sites/plans/selectors/get-plans-by-site' );
3334
jest.mock( 'calypso/my-sites/checkout/use-cart-key' );
3435
jest.mock( 'calypso/lib/analytics/utils/refresh-country-code-cookie-gdpr' );
36+
jest.mock( 'calypso/state/products-list/selectors/is-marketplace-product' );
3537

3638
/* eslint-disable jest/no-conditional-expect */
3739

@@ -45,6 +47,7 @@ describe( 'CompositeCheckout with a variant picker', () => {
4547
} ) );
4648
hasLoadedSiteDomains.mockImplementation( () => true );
4749
getDomainsBySiteId.mockImplementation( () => [] );
50+
isMarketplaceProduct.mockImplementation( () => false );
4851

4952
const initialCart = {
5053
coupon: '',

client/my-sites/checkout/composite-checkout/test/composite-checkout.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import page from 'page';
1717
import { Provider as ReduxProvider } from 'react-redux';
1818
import '@testing-library/jest-dom/extend-expect';
1919
import useCartKey from 'calypso/my-sites/checkout/use-cart-key';
20+
import { isMarketplaceProduct } from 'calypso/state/products-list/selectors';
2021
import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer';
2122
import { getDomainsBySiteId, hasLoadedSiteDomains } from 'calypso/state/sites/domains/selectors';
2223
import { getPlansBySiteId } from 'calypso/state/sites/plans/selectors/get-plans-by-site';
@@ -46,6 +47,7 @@ jest.mock( 'calypso/state/selectors/is-site-automated-transfer' );
4647
jest.mock( 'calypso/state/sites/plans/selectors/get-plans-by-site' );
4748
jest.mock( 'calypso/my-sites/checkout/use-cart-key' );
4849
jest.mock( 'calypso/lib/analytics/utils/refresh-country-code-cookie-gdpr' );
50+
jest.mock( 'calypso/state/products-list/selectors/is-marketplace-product' );
4951

5052
jest.mock( 'page', () => ( {
5153
redirect: jest.fn(),
@@ -62,6 +64,7 @@ describe( 'CompositeCheckout', () => {
6264
} ) );
6365
hasLoadedSiteDomains.mockImplementation( () => true );
6466
getDomainsBySiteId.mockImplementation( () => [] );
67+
isMarketplaceProduct.mockImplementation( () => false );
6568

6669
container = document.createElement( 'div' );
6770
document.body.appendChild( container );

0 commit comments

Comments
 (0)