auto_commit(false); if (isset($post['a2w_import_language'])) { set_setting('import_language', wp_unslash($post['a2w_import_language'])); } if (isset($post['a2w_local_currency'])) { $currency = wp_unslash($post['a2w_local_currency']); set_setting('local_currency', $currency); update_option('woocommerce_currency', $currency); } // description import mode $mode = $post['a2wl_description_import_mode'] ?? 'use_spec'; set_setting('not_import_attributes', false); set_setting('not_import_description', $mode === 'use_spec'); set_setting('not_import_description_images', $mode === 'use_spec'); $pricingRules = $post['a2wl_pricing_rules'] ?? 'safe-start-x3'; $addShipping = isset($post['a2wl_add_shipping_to_product']); $this->setupPricingRules($pricingRules, $addShipping); if (isset($post['a2wl_remove_unwanted_phrases'])) { PhraseFilter::deleteAll(); foreach (['China','china','Aliexpress','AliExpress'] as $phrase) { (new PhraseFilter(['phrase' => $phrase, 'phrase_replace' => '']))->save(); } } if (!empty($post['a2wl_fulfillment_phone_code']) && !empty($post['a2wl_fulfillment_phone_number'])) { set_setting('fulfillment_phone_code', wp_unslash($post['a2wl_fulfillment_phone_code'])); set_setting('fulfillment_phone_number', wp_unslash($post['a2wl_fulfillment_phone_number'])); } else { $errors['a2wl_fulfillment_phone_block'] = esc_html__('required fields', 'ali2woo'); } settings()->commit(); settings()->auto_commit(true); return $errors; } protected function setupPricingRules(string $pricingRules, bool $addShipping): void { set_setting('pricing_rules_type', PriceFormulaService::SALE_PRICE_AS_BASE); set_setting('use_extended_price_markup', false); set_setting('use_compared_price_markup', false); set_setting('price_cents', -1); set_setting('price_compared_cents', -1); set_setting('default_formula', false); $this->PriceFormulaRepository->deleteAll(); if ($pricingRules === 'safe-start-x3') { $defaultRule = [ 'value' => 3, 'sign' => '*', 'compared_value' => 3.5, 'compared_sign' => '*' ]; $formula = $this->PriceFormulaFactory->createFormulaFromData($defaultRule); $this->PriceFormulaRepository->setDefaultFormula($formula); set_setting('price_cents', 99); } else if ($pricingRules === 'aggressive-x4') { $defaultRule = [ 'value' => 4, 'sign' => '*', 'compared_value' => 4.5, 'compared_sign' => '*' ]; $formula = $this->PriceFormulaFactory->createFormulaFromData($defaultRule); $this->PriceFormulaRepository->setDefaultFormula($formula); set_setting('price_cents', 99); } else if ($pricingRules === 'fixed-plus-10') { $defaultRule = [ 'value' => 10, 'sign' => '+', 'compared_value' => 15, 'compared_sign' => '+' ]; $formula = $this->PriceFormulaFactory->createFormulaFromData($defaultRule); $this->PriceFormulaRepository->setDefaultFormula($formula); set_setting('price_cents', -1); } } public function collectModel(): array { $language_model = new Language(); return [ 'aliexpressRegion' => $this->AliexpressRegionRepository->get(), 'aliexpressRegions' => $this->AliexpressRegionRepository->getAllWithLabels(), 'currencies' => $this->AliexpressLocalizator->getCurrencies(false), 'custom_currencies' => $this->AliexpressLocalizator->getCurrencies(true), 'description_import_modes' => [ 'use_spec' => esc_html_x('Use specifications only (recommended)', 'Wizard', 'ali2woo'), 'import_desc' => esc_html_x('Use AliExpress description', 'Wizard', 'ali2woo'), ], 'pricing_rule_sets' => [ 'safe-start-x3' => esc_html_x('Multiply by 3 (recommended)', 'Wizard', 'ali2woo'), 'aggressive-x4' => esc_html_x('Multiply by 4', 'Wizard', 'ali2woo'), 'fixed-plus-10' => esc_html_x('Add fixed amount', 'Wizard', 'ali2woo'), 'no' => esc_html_x('Skip for now', 'Wizard', 'ali2woo'), ], 'pricing_rule_descriptions' => [ 'safe-start-x3' => _x('Recommended for beginners. Sells products at 3× the AliExpress price. Example: $10 → $29.99.', 'Wizard', 'ali2woo'), 'aggressive-x4' => _x('For cheap impulse products under $5 promoted with TikTok or Reels ads. Example: $4 → $15.99.', 'Wizard', 'ali2woo'), 'fixed-plus-10' => _x('For products over $20: adds $10 to the price and $15 to the compare-at price. Example: $25 → $34.99.', 'Wizard', 'ali2woo'), 'no' => _x('Imports products with AliExpress prices as-is. Configure pricing rules before running ads, otherwise you risk selling at a loss.', 'Wizard', 'ali2woo'), ], 'shippingModes' => [ 'no' => esc_html_x('No need', 'Wizard', 'ali2woo'), 'cart_page' => esc_html_x('Use only in cart', 'Wizard', 'ali2woo'), 'product_page' => esc_html_x('Use in cart and product page ', 'Wizard', 'ali2woo'), ], 'languages' => $language_model->get_languages(), 'wizardLogo' => $this->AssetService->getLogoUrl('logo-120.png') ]; } }