Skip to content

Commit

Permalink
Marketplace: clean up and setup paid plugins purchase flow (#59065)
Browse files Browse the repository at this point in the history
* 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 <papazoglou.charalampos@gmail.com>
  • Loading branch information
cpapazoglou and cpap committed Dec 14, 2021
1 parent c8471ef commit ba2918d
Show file tree
Hide file tree
Showing 35 changed files with 68 additions and 1,782 deletions.

This file was deleted.

@@ -1,4 +1,4 @@
import { isPremium } from '@automattic/calypso-products';
import { isPremium, isBusiness } from '@automattic/calypso-products';
import { FormStatus, useFormStatus } from '@automattic/composite-checkout';
import {
getCouponLineItemFromCart,
Expand All @@ -11,7 +11,9 @@ import {
import styled from '@emotion/styled';
import PropTypes from 'prop-types';
import * as React from 'react';
import { useSelector } from 'react-redux';
import { hasDIFMProduct } from 'calypso/lib/cart-values/cart-items';
import { isMarketplaceProduct } from 'calypso/state/products-list/selectors';
import { ItemVariationPicker } from './item-variation-picker';
import type { OnChangeItemVariant } from './item-variation-picker';
import type { Theme } from '@automattic/composite-checkout';
Expand Down Expand Up @@ -77,6 +79,11 @@ export function WPOrderReviewLineItems( {
const couponLineItem = getCouponLineItemFromCart( responseCart );
const { formStatus } = useFormStatus();
const isDisabled = formStatus !== FormStatus.READY;
const hasMarketplaceProduct = useSelector( ( state ) =>
responseCart.products.some( ( product: ResponseCartProduct ) =>
isMarketplaceProduct( state, product.product_slug )
)
);

return (
<WPOrderReviewList className={ joinClasses( [ className, 'order-review-line-items' ] ) }>
Expand All @@ -90,7 +97,7 @@ export function WPOrderReviewLineItems( {
<WPOrderReviewListItem key={ product.uuid }>
<LineItem
product={ product }
hasDeleteButton={ canItemBeDeleted( product, responseCart ) }
hasDeleteButton={ canItemBeDeleted( product, responseCart, hasMarketplaceProduct ) }
removeProductFromCart={ removeProductFromCart }
isSummary={ isSummary }
createUserAndSiteBeforeTransaction={ createUserAndSiteBeforeTransaction }
Expand Down Expand Up @@ -149,23 +156,28 @@ WPOrderReviewLineItems.propTypes = {

/**
* Checks if the given item is the premium plan product and the DIFM product exists in the provided shopping cart object
*
* @param item The shopping basket line item
* @param cartProducts The shopping cart object
* @returns boolean
*/
function isPremiumPlanWithDIFMInTheCart( item: ResponseCartProduct, cartProducts: ResponseCart ) {
return isPremium( item ) && hasDIFMProduct( cartProducts );
function isPremiumPlanWithDIFMInTheCart( item: ResponseCartProduct, responseCart: ResponseCart ) {
return isPremium( item ) && hasDIFMProduct( responseCart );
}

function canItemBeDeleted( item: ResponseCartProduct, cartProducts: ResponseCart ): boolean {
function canItemBeDeleted(
item: ResponseCartProduct,
responseCart: ResponseCart,
hasMarketplaceProduct: boolean
): boolean {
const itemTypesThatCannotBeDeleted = [ 'domain_redemption' ];
if ( itemTypesThatCannotBeDeleted.includes( item.product_slug ) ) {
return false;
}

// The Premium plan cannot be removed from the cart when in combination with the DIFM lite product
if ( isPremiumPlanWithDIFMInTheCart( item, cartProducts ) ) {
if ( isPremiumPlanWithDIFMInTheCart( item, responseCart ) ) {
return false;
}

// The Business plan cannot be removed from the cart when in combination with a marketplace product
if ( isBusiness( item ) && hasMarketplaceProduct ) {
return false;
}
return true;
Expand Down
Expand Up @@ -7,6 +7,7 @@ import { render, fireEvent, screen, within } from '@testing-library/react';
import { Provider as ReduxProvider } from 'react-redux';
import '@testing-library/jest-dom/extend-expect';
import useCartKey from 'calypso/my-sites/checkout/use-cart-key';
import { isMarketplaceProduct } from 'calypso/state/products-list/selectors';
import { getDomainsBySiteId, hasLoadedSiteDomains } from 'calypso/state/sites/domains/selectors';
import { getPlansBySiteId } from 'calypso/state/sites/plans/selectors/get-plans-by-site';
import CompositeCheckout from '../composite-checkout';
Expand All @@ -32,6 +33,7 @@ jest.mock( 'calypso/state/selectors/is-site-automated-transfer' );
jest.mock( 'calypso/state/sites/plans/selectors/get-plans-by-site' );
jest.mock( 'calypso/my-sites/checkout/use-cart-key' );
jest.mock( 'calypso/lib/analytics/utils/refresh-country-code-cookie-gdpr' );
jest.mock( 'calypso/state/products-list/selectors/is-marketplace-product' );

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

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

const initialCart = {
coupon: '',
Expand Down
Expand Up @@ -17,6 +17,7 @@ import page from 'page';
import { Provider as ReduxProvider } from 'react-redux';
import '@testing-library/jest-dom/extend-expect';
import useCartKey from 'calypso/my-sites/checkout/use-cart-key';
import { isMarketplaceProduct } from 'calypso/state/products-list/selectors';
import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer';
import { getDomainsBySiteId, hasLoadedSiteDomains } from 'calypso/state/sites/domains/selectors';
import { getPlansBySiteId } from 'calypso/state/sites/plans/selectors/get-plans-by-site';
Expand Down Expand Up @@ -46,6 +47,7 @@ jest.mock( 'calypso/state/selectors/is-site-automated-transfer' );
jest.mock( 'calypso/state/sites/plans/selectors/get-plans-by-site' );
jest.mock( 'calypso/my-sites/checkout/use-cart-key' );
jest.mock( 'calypso/lib/analytics/utils/refresh-country-code-cookie-gdpr' );
jest.mock( 'calypso/state/products-list/selectors/is-marketplace-product' );

jest.mock( 'page', () => ( {
redirect: jest.fn(),
Expand All @@ -62,6 +64,7 @@ describe( 'CompositeCheckout', () => {
} ) );
hasLoadedSiteDomains.mockImplementation( () => true );
getDomainsBySiteId.mockImplementation( () => [] );
isMarketplaceProduct.mockImplementation( () => false );

container = document.createElement( 'div' );
document.body.appendChild( container );
Expand Down

0 comments on commit ba2918d

Please sign in to comment.