Skip to content

Commit

Permalink
Jetpack Search: enable purchases via "...search/yearly" routes. (#43865)
Browse files Browse the repository at this point in the history
* Enable processing of the yearly plans.

Those are defined adding /yearly to the url. We take those as default
and skip including yearly in product type slug. So e.g. jetpack_search
is the yearly version, while jetpack_search_monthly, its monthly
version.

* Correct product name retrieval.

It would not work with the new route, which is shorter.

* Jetpack Search for Jetpack sites should redirect to the checkout screen.

Atm it is adding an empty product to the Cart and redirecting to /plans.
  • Loading branch information
AnnaMag authored Jul 2, 2020
1 parent 8cf1238 commit 717a031
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
18 changes: 6 additions & 12 deletions client/jetpack-connect/jetpack-connection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import debugModule from 'debug';
import config from 'config';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { flowRight, get, includes, startsWith, omit } from 'lodash';
import { flowRight, get, includes, omit } from 'lodash';
import { localize } from 'i18n-calypso';

/**
Expand Down Expand Up @@ -197,9 +197,12 @@ const jetpackConnection = ( WrappedComponent ) => {
}

if ( this.checkProperty( 'isWordPressDotCom' ) ) {
const product = window.location.href.split( '/' )[ 5 ];
const product_path = window.location.pathname;

if ( startsWith( product, 'jetpack_search' ) || startsWith( product, 'wpcom_search' ) ) {
if (
product_path.includes( 'jetpack_search' ) ||
product_path.includes( 'wpcom_search' )
) {
return IS_DOT_COM_GET_SEARCH;
}
return IS_DOT_COM;
Expand All @@ -209,15 +212,6 @@ const jetpackConnection = ( WrappedComponent ) => {
return SITE_BLOCKED;
}

if ( this.checkProperty( 'isWordPressDotCom' ) ) {
const product = window.location.href.split( '/' )[ 5 ];

if ( startsWith( product, 'jetpack_search' ) ) {
return IS_DOT_COM_GET_SEARCH;
}
return IS_DOT_COM;
}

if ( this.props.jetpackConnectSite.installConfirmedByUser === false ) {
return NOT_JETPACK;
}
Expand Down
14 changes: 11 additions & 3 deletions client/jetpack-connect/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,18 @@ export class SearchPurchase extends Component {
}

getProduct() {
const product = window.location.pathname.split( '/' )[ 3 ];
const type = window.location.pathname.split( '/' )[ 4 ];
const type = window.location.pathname.includes( 'monthly' ) && 'monthly';
let product = '';

return [ 'monthly', 'yearly' ].includes( type ) ? product + '_' + type : product;
if ( window.location.pathname.includes( 'jetpack_search' ) ) {
product = type ? 'jetpack_search_monthly' : 'jetpack_search';
}

if ( window.location.pathname.includes( 'wpcom_search' ) ) {
product = type ? 'wpcom_search_monthly' : 'wpcom_search';
}

return product;
}

renderSiteInput( status ) {
Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/checkout/checkout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class Checkout extends React.Component {
? jetpackProductItem( 'wpcom_search_monthly' )
: jetpackProductItem( 'wpcom_search' );
} else {
cartItem = null;
cartItem = ! isJetpackNotAtomic ? null : cartItem;
}
}

Expand Down

0 comments on commit 717a031

Please sign in to comment.