Skip to content

Commit

Permalink
Merge pull request #928 from woocommerce/add/four-onboarding-steps
Browse files Browse the repository at this point in the history
Add fourth MC Setup step value: 'store_requirements'
  • Loading branch information
layoutd authored Aug 5, 2021
2 parents d1d1b51 + eed3293 commit c1f9aee
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/MerchantCenter/MerchantCenterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter;

use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\Settings;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingRateQuery;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingTimeQuery;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\MerchantIssueTable;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\ShippingRateTable;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\ShippingTimeTable;
Expand Down Expand Up @@ -137,7 +139,7 @@ public function is_contact_information_setup(): bool {
return true;
}

// Additional check for users that have already gone through onboarding.
// Additional check for users that have already gone through on-boarding.
if ( $this->is_setup_complete() ) {
$is_mc_setup = $this->is_mc_contact_information_setup();
$this->options->update( OptionsInterface::CONTACT_INFO_SETUP, $is_mc_setup );
Expand Down Expand Up @@ -220,6 +222,10 @@ public function get_setup_status(): array {

if ( $this->saved_target_audience() ) {
$step = 'shipping_and_taxes';

if ( $this->saved_shipping_and_tax_options() ) {
$step = 'store_requirements';
}
}
}

Expand Down Expand Up @@ -334,4 +340,43 @@ protected function is_mc_contact_information_setup(): bool {

return $is_setup['phone_number'] && $is_setup['address'];
}

/**
* Check if the taxes + shipping rate and time + free shipping settings have been saved.
*
* @return bool If all required settings have been provided.
*
* @since x.x.x
*/
protected function saved_shipping_and_tax_options(): bool {
$merchant_center_settings = $this->options->get( OptionsInterface::MERCHANT_CENTER, [] );
$target_countries = $this->get_target_countries();

// Tax options saved if: not US (no taxes) or tax_rate has been set
if ( in_array( 'US', $target_countries, true ) && empty( $merchant_center_settings['tax_rate'] ) ) {
return false;
}

// Free shipping saved if: not offered, OR offered and threshold not null
if ( ! empty( $merchant_center_settings['offers_free_shipping'] ) && ! isset( $merchant_center_settings['free_shipping_threshold'] ) ) {
return false;
}

// Shipping options saved if: 'manual' OR records for all countries
if ( isset( $merchant_center_settings['shipping_time'] ) && 'manual' === $merchant_center_settings['shipping_time'] ) {
$saved_shipping_time = true;
} else {
$shipping_time_rows = $this->container->get( ShippingTimeQuery::class )->get_count();
$saved_shipping_time = $shipping_time_rows === count( $target_countries );
}

if ( isset( $merchant_center_settings['shipping_rate'] ) && 'manual' === $merchant_center_settings['shipping_rate'] ) {
$saved_shipping_rate = true;
} else {
$shipping_rate_rows = $this->container->get( ShippingRateQuery::class )->get_count();
$saved_shipping_rate = $shipping_rate_rows === count( $target_countries );
}

return $saved_shipping_rate && $saved_shipping_time;
}
}

0 comments on commit c1f9aee

Please sign in to comment.