2019-12-20 12:58:38 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import { Button, Modal } from '@wordpress/components';
|
|
|
|
import { find } from 'lodash';
|
|
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
2020-05-28 08:51:40 +00:00
|
|
|
import { withSelect } from '@wordpress/data';
|
2019-12-20 12:58:38 +00:00
|
|
|
import { List } from '@woocommerce/components';
|
2020-05-28 08:51:40 +00:00
|
|
|
import { ONBOARDING_STORE_NAME, PLUGINS_STORE_NAME } from '@woocommerce/data';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2019-12-20 12:58:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-08-13 02:05:22 +00:00
|
|
|
import { getProductIdsForCart } from '../utils';
|
|
|
|
import sanitizeHTML from '../../lib/sanitize-html';
|
|
|
|
import { getInAppPurchaseUrl } from '../../lib/in-app-purchase';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2019-12-20 12:58:38 +00:00
|
|
|
|
|
|
|
class CartModal extends Component {
|
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
|
|
|
this.state = {
|
|
|
|
purchaseNowButtonBusy: false,
|
|
|
|
purchaseLaterButtonBusy: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickPurchaseNow() {
|
|
|
|
const { productIds, onClickPurchaseNow } = this.props;
|
|
|
|
this.setState( { purchaseNowButtonBusy: true } );
|
|
|
|
if ( ! productIds.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-02 02:36:25 +00:00
|
|
|
recordEvent( 'tasklist_modal_proceed_checkout', {
|
|
|
|
product_ids: productIds,
|
2020-03-03 09:44:26 +00:00
|
|
|
purchase_install: true,
|
2020-01-02 02:36:25 +00:00
|
|
|
} );
|
|
|
|
|
2021-08-03 20:56:43 +00:00
|
|
|
const url = getInAppPurchaseUrl(
|
2023-11-06 11:45:26 +00:00
|
|
|
'https://woo.com/cart?utm_medium=product',
|
2021-08-03 20:56:43 +00:00
|
|
|
{
|
|
|
|
'wccom-replace-with': productIds.join( ',' ),
|
|
|
|
}
|
|
|
|
);
|
2019-12-20 12:58:38 +00:00
|
|
|
|
|
|
|
if ( onClickPurchaseNow ) {
|
|
|
|
onClickPurchaseNow( url );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.location = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickPurchaseLater() {
|
2020-01-02 02:36:25 +00:00
|
|
|
const { productIds } = this.props;
|
|
|
|
|
|
|
|
recordEvent( 'tasklist_modal_proceed_checkout', {
|
|
|
|
product_ids: productIds,
|
|
|
|
purchase_install: false,
|
|
|
|
} );
|
|
|
|
|
2019-12-20 12:58:38 +00:00
|
|
|
this.setState( { purchaseLaterButtonBusy: true } );
|
|
|
|
this.props.onClickPurchaseLater();
|
|
|
|
}
|
|
|
|
|
2020-01-02 02:36:25 +00:00
|
|
|
onClose() {
|
|
|
|
const { onClose, productIds } = this.props;
|
|
|
|
|
|
|
|
recordEvent( 'tasklist_modal_proceed_checkout', {
|
|
|
|
product_ids: productIds,
|
|
|
|
purchase_install: false,
|
|
|
|
} );
|
|
|
|
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:58:38 +00:00
|
|
|
renderProducts() {
|
2021-10-13 16:15:47 +00:00
|
|
|
const { productIds, productTypes } = this.props;
|
2022-01-06 12:53:30 +00:00
|
|
|
const { themes = [] } = getAdminSetting( 'onboarding', {} );
|
2019-12-20 12:58:38 +00:00
|
|
|
const listItems = [];
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
productIds.forEach( ( productId ) => {
|
|
|
|
const productInfo = find( productTypes, ( productType ) => {
|
2019-12-20 12:58:38 +00:00
|
|
|
return productType.product === productId;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( productInfo ) {
|
|
|
|
listItems.push( {
|
|
|
|
title: productInfo.label,
|
|
|
|
content: productInfo.description,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const themeInfo = find( themes, ( theme ) => {
|
2019-12-20 12:58:38 +00:00
|
|
|
return theme.id === productId;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( themeInfo ) {
|
|
|
|
listItems.push( {
|
|
|
|
title: sprintf(
|
2023-11-16 11:15:11 +00:00
|
|
|
/* translators: 1: theme title, 2: theme price */
|
|
|
|
__( '%1$s — %2$s per year', 'woocommerce' ),
|
2019-12-20 12:58:38 +00:00
|
|
|
themeInfo.title,
|
|
|
|
decodeEntities( themeInfo.price )
|
|
|
|
),
|
2020-02-14 02:23:21 +00:00
|
|
|
content: (
|
|
|
|
<span
|
|
|
|
dangerouslySetInnerHTML={ sanitizeHTML(
|
|
|
|
themeInfo.excerpt
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
),
|
2019-12-20 12:58:38 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
return <List items={ listItems } />;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { purchaseNowButtonBusy, purchaseLaterButtonBusy } = this.state;
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title={ __(
|
2020-12-01 11:55:27 +00:00
|
|
|
'Would you like to add the following paid features to your store now?',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2019-12-20 12:58:38 +00:00
|
|
|
) }
|
2020-01-02 02:36:25 +00:00
|
|
|
onRequestClose={ () => this.onClose() }
|
2019-12-20 12:58:38 +00:00
|
|
|
className="woocommerce-cart-modal"
|
|
|
|
>
|
|
|
|
{ this.renderProducts() }
|
|
|
|
|
|
|
|
<p className="woocommerce-cart-modal__help-text">
|
|
|
|
{ __(
|
|
|
|
"You won't have access to this functionality until the extensions have been purchased and installed.",
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2019-12-20 12:58:38 +00:00
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<div className="woocommerce-cart-modal__actions">
|
|
|
|
<Button
|
|
|
|
isLink
|
|
|
|
isBusy={ purchaseLaterButtonBusy }
|
|
|
|
onClick={ () => this.onClickPurchaseLater() }
|
|
|
|
>
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( "I'll do it later", 'woocommerce' ) }
|
2019-12-20 12:58:38 +00:00
|
|
|
</Button>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
isPrimary
|
|
|
|
isBusy={ purchaseNowButtonBusy }
|
|
|
|
onClick={ () => this.onClickPurchaseNow() }
|
|
|
|
>
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Buy now', 'woocommerce' ) }
|
2019-12-20 12:58:38 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
2020-02-14 02:23:21 +00:00
|
|
|
withSelect( ( select ) => {
|
2020-05-25 00:26:08 +00:00
|
|
|
const { getInstalledPlugins } = select( PLUGINS_STORE_NAME );
|
2021-10-13 16:15:47 +00:00
|
|
|
const { getProductTypes, getProfileItems } = select(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
);
|
2019-12-20 12:58:38 +00:00
|
|
|
const profileItems = getProfileItems();
|
2020-05-25 00:26:08 +00:00
|
|
|
const installedPlugins = getInstalledPlugins();
|
2021-10-13 16:15:47 +00:00
|
|
|
const productTypes = getProductTypes();
|
2020-05-25 00:26:08 +00:00
|
|
|
const productIds = getProductIdsForCart(
|
2021-10-13 16:15:47 +00:00
|
|
|
productTypes,
|
2020-05-25 00:26:08 +00:00
|
|
|
profileItems,
|
|
|
|
false,
|
|
|
|
installedPlugins
|
|
|
|
);
|
2019-12-20 12:58:38 +00:00
|
|
|
|
2021-10-13 16:15:47 +00:00
|
|
|
return { profileItems, productIds, productTypes };
|
2019-12-20 12:58:38 +00:00
|
|
|
} )
|
|
|
|
)( CartModal );
|