| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of WizardService |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace AliNext_Lite;; |
| 10 |
|
| 11 |
class WizardService |
| 12 |
{ |
| 13 |
public function __construct( |
| 14 |
protected AliexpressRegionRepository $AliexpressRegionRepository, |
| 15 |
protected AliexpressLocalizator $AliexpressLocalizator, |
| 16 |
protected PriceFormulaRepository $PriceFormulaRepository, |
| 17 |
protected PriceFormulaFactory $PriceFormulaFactory, |
| 18 |
protected CommonSettingService $CommonSettingService, |
| 19 |
protected AssetService $AssetService |
| 20 |
) { |
| 21 |
} |
| 22 |
|
| 23 |
public function handle(array $post): array |
| 24 |
{ |
| 25 |
$errors = []; |
| 26 |
|
| 27 |
settings()->auto_commit(false); |
| 28 |
|
| 29 |
|
| 30 |
if (isset($post['a2w_import_language'])) { |
| 31 |
set_setting('import_language', wp_unslash($post['a2w_import_language'])); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
if (isset($post['a2w_local_currency'])) { |
| 37 |
$currency = wp_unslash($post['a2w_local_currency']); |
| 38 |
set_setting('local_currency', $currency); |
| 39 |
update_option('woocommerce_currency', $currency); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
// description import mode |
| 45 |
$mode = $post['a2wl_description_import_mode'] ?? 'use_spec'; |
| 46 |
set_setting('not_import_attributes', false); |
| 47 |
set_setting('not_import_description', $mode === 'use_spec'); |
| 48 |
set_setting('not_import_description_images', $mode === 'use_spec'); |
| 49 |
|
| 50 |
$pricingRules = $post['a2wl_pricing_rules'] ?? 'low-ticket-fixed-3000'; |
| 51 |
$addShipping = isset($post['a2wl_add_shipping_to_product']); |
| 52 |
|
| 53 |
$this->setupPricingRules($pricingRules, $addShipping); |
| 54 |
|
| 55 |
if (isset($post['a2wl_remove_unwanted_phrases'])) { |
| 56 |
PhraseFilter::deleteAll(); |
| 57 |
foreach (['China','china','Aliexpress','AliExpress'] as $phrase) { |
| 58 |
(new PhraseFilter(['phrase' => $phrase, 'phrase_replace' => '']))->save(); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
if (!empty($post['a2wl_fulfillment_phone_code']) && !empty($post['a2wl_fulfillment_phone_number'])) { |
| 63 |
set_setting('fulfillment_phone_code', wp_unslash($post['a2wl_fulfillment_phone_code'])); |
| 64 |
set_setting('fulfillment_phone_number', wp_unslash($post['a2wl_fulfillment_phone_number'])); |
| 65 |
} else { |
| 66 |
$errors['a2wl_fulfillment_phone_block'] = esc_html__('required fields', 'ali2woo'); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
settings()->commit(); |
| 73 |
settings()->auto_commit(true); |
| 74 |
|
| 75 |
return $errors; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
protected function setupPricingRules(string $pricingRules, bool $addShipping): void |
| 81 |
{ |
| 82 |
set_setting('pricing_rules_type', PriceFormulaService::SALE_PRICE_AS_BASE); |
| 83 |
set_setting('use_extended_price_markup', false); |
| 84 |
set_setting('use_compared_price_markup', false); |
| 85 |
set_setting('price_cents', -1); |
| 86 |
set_setting('price_compared_cents', -1); |
| 87 |
set_setting('default_formula', false); |
| 88 |
|
| 89 |
$this->PriceFormulaRepository->deleteAll(); |
| 90 |
|
| 91 |
if ($pricingRules === 'low-ticket-fixed-3000') { |
| 92 |
$defaultRule = [ |
| 93 |
'value' => 3, |
| 94 |
'sign' => '*', |
| 95 |
'compared_value' => 1, |
| 96 |
'compared_sign' => '*' |
| 97 |
]; |
| 98 |
$formula = $this->PriceFormulaFactory->createFormulaFromData($defaultRule); |
| 99 |
$this->PriceFormulaRepository->setDefaultFormula($formula); |
| 100 |
} |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
public function collectModel(): array |
| 105 |
{ |
| 106 |
$language_model = new Language(); |
| 107 |
|
| 108 |
return [ |
| 109 |
'aliexpressRegion' => $this->AliexpressRegionRepository->get(), |
| 110 |
'aliexpressRegions' => $this->AliexpressRegionRepository->getAllWithLabels(), |
| 111 |
'currencies' => $this->AliexpressLocalizator->getCurrencies(false), |
| 112 |
'custom_currencies' => $this->AliexpressLocalizator->getCurrencies(true), |
| 113 |
'description_import_modes' => [ |
| 114 |
'use_spec' => esc_html_x('Use specifications only (recommended)', 'Wizard', 'ali2woo'), |
| 115 |
'import_desc' => esc_html_x('Use AliExpress description', 'Wizard', 'ali2woo'), |
| 116 |
], |
| 117 |
'pricing_rule_sets' => [ |
| 118 |
'no' => esc_html_x('Skip for now', 'Wizard', 'ali2woo'), |
| 119 |
'low-ticket-fixed-3000' => esc_html_x('Fixed markup 300%', 'Wizard', 'ali2woo'), |
| 120 |
], |
| 121 |
'shippingModes' => [ |
| 122 |
'no' => esc_html_x('No need', 'Wizard', 'ali2woo'), |
| 123 |
'cart_page' => esc_html_x('Use only in cart', 'Wizard', 'ali2woo'), |
| 124 |
'product_page' => esc_html_x('Use in cart and product page ', 'Wizard', 'ali2woo'), |
| 125 |
], |
| 126 |
'languages' => $language_model->get_languages(), |
| 127 |
'wizardLogo' => $this->AssetService->getLogoUrl('logo-120.png') |
| 128 |
]; |
| 129 |
} |
| 130 |
} |
| 131 |
|