| @@ -1,120 +1,57 @@ | ||
| 1 | -<?php | |
| 1 | +<?php namespace TierPricingTable\Admin; | |
| 2 | 2 | |
| 3 | -namespace TierPricingTable\Admin; | |
| 3 | +use TierPricingTable\Admin\ProductPage\AdvanceOptionsForVariableProduct; | |
| 4 | +use TierPricingTable\Admin\ProductPage\Product; | |
| 5 | +use TierPricingTable\Admin\ProductPage\TieredPricingTab; | |
| 6 | +use TierPricingTable\Admin\ProductPage\RoleCustomerPricingTab; | |
| 7 | +use TierPricingTable\Admin\WelcomePage\WelcomePage; | |
| 8 | +use TierPricingTable\Core\ServiceContainerTrait; | |
| 9 | +use TierPricingTable\TierPricingTablePlugin; | |
| 10 | +use TierPricingTable\Admin\Tips\TipsManager; | |
| 4 | 11 | |
| 5 | -use TierPricingTable\Freemius ; | |
| 6 | -use TierPricingTable\Settings\Settings ; | |
| 7 | -use TierPricingTable\TierPricingTablePlugin ; | |
| 8 | -use Premmerce\SDK\V2\FileManager\FileManager ; | |
| 9 | -use TierPricingTable\Admin\ProductManagers\SimpleProductManager ; | |
| 10 | -use TierPricingTable\Admin\ProductManagers\VariationProductManager ; | |
| 11 | -use TierPricingTable\Admin\Export\Woocommerce as WooCommerceExport ; | |
| 12 | -use TierPricingTable\Admin\Import\Woocommerce as WooCommerceImport ; | |
| 13 | 12 | /** |
| 14 | 13 | * Class Admin |
| 15 | 14 | * |
| 16 | 15 | * @package TierPricingTable\Admin |
| 17 | 16 | */ |
| 18 | -class Admin | |
| 19 | -{ | |
| 20 | - /** | |
| 21 | - * @var FileManager | |
| 22 | - */ | |
| 23 | - private $fileManager ; | |
| 24 | - /** | |
| 25 | - * @var Settings | |
| 26 | - */ | |
| 27 | - private $settings ; | |
| 28 | - /** | |
| 29 | - * @var array | |
| 30 | - */ | |
| 31 | - private $managers ; | |
| 32 | - /** | |
| 33 | - * @var Freemius | |
| 34 | - */ | |
| 35 | - private $licence ; | |
| 36 | - /** | |
| 37 | - * Admin constructor. | |
| 38 | - * | |
| 39 | - * Register menu items and handlers | |
| 40 | - * | |
| 41 | - * @param FileManager $fileManager | |
| 42 | - * @param Freemius $licence | |
| 43 | - * @param Settings $settings | |
| 44 | - */ | |
| 45 | - public function __construct( FileManager $fileManager, Freemius $licence, Settings $settings ) | |
| 46 | - { | |
| 47 | - $this->fileManager = $fileManager; | |
| 48 | - $this->settings = $settings; | |
| 49 | - $this->licence = $licence; | |
| 50 | - $this->initManagers(); | |
| 51 | - add_action( 'admin_enqueue_scripts', [ $this, 'enqueueAssets' ] ); | |
| 52 | - if ( get_transient( 'tier_pricing_table_activated' ) ) { | |
| 53 | - add_action( 'admin_notices', [ $this, 'showActivationMessage' ] ); | |
| 54 | - } | |
| 55 | - | |
| 56 | - if ( $this->licence->isFree() ) { | |
| 57 | - $template = 'upgrade-alert.php'; | |
| 58 | - add_action( 'woocommerce_settings_' . Settings::SETTINGS_PAGE, function () use( $template ) { | |
| 59 | - $this->fileManager->includeTemplate( 'admin/alerts/' . $template, [ | |
| 60 | - 'upgradeUrl' => tpt_fs()->get_upgrade_url(), | |
| 61 | - 'contactUsUrl' => $this->licence->getContactUsPageUrl(), | |
| 62 | - ] ); | |
| 63 | - $this->fileManager->includeTemplate( 'admin/only-in-premium-script.php' ); | |
| 64 | - } ); | |
| 65 | - } | |
| 66 | - | |
| 67 | - } | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * Init Managers | |
| 71 | - */ | |
| 72 | - public function initManagers() | |
| 73 | - { | |
| 74 | - $this->managers = [ | |
| 75 | - SimpleProductManager::class => new SimpleProductManager( $this->fileManager, $this->settings, $this->licence ), | |
| 76 | - VariationProductManager::class => new VariationProductManager( $this->fileManager, $this->settings, $this->licence ), | |
| 77 | - WooCommerceExport::class => new WooCommerceExport(), | |
| 78 | - WooCommerceImport::class => new WooCommerceImport(), | |
| 79 | - ]; | |
| 80 | - } | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * Show message about activation plugin and advise next step | |
| 84 | - */ | |
| 85 | - public function showActivationMessage() | |
| 86 | - { | |
| 87 | - $link = $this->settings->getLink(); | |
| 88 | - $this->fileManager->includeTemplate( 'admin/alerts/activation-alert.php', [ | |
| 89 | - 'link' => $link, | |
| 90 | - ] ); | |
| 91 | - delete_transient( 'tiered_pricing_table_activated' ); | |
| 92 | - } | |
| 93 | - | |
| 94 | - /** | |
| 95 | - * Register assets on product create/update page | |
| 96 | - * | |
| 97 | - * @param $page | |
| 98 | - */ | |
| 99 | - public function enqueueAssets( $page ) | |
| 100 | - { | |
| 101 | - global $post, $page ; | |
| 102 | - | |
| 103 | - if ( isset( $_GET['tab'] ) && $_GET['tab'] == Settings::SETTINGS_PAGE || ($page == 'post.php' || ($page = 'post_new.php')) && $post && $post->post_type == 'product' ) { | |
| 104 | - wp_enqueue_script( | |
| 105 | - 'tier-pricing-table-admin-js', | |
| 106 | - $this->fileManager->locateAsset( 'admin/main.js' ), | |
| 107 | - 'jquery', | |
| 108 | - TierPricingTablePlugin::VERSION | |
| 109 | - ); | |
| 110 | - wp_enqueue_style( | |
| 111 | - 'tier-pricing-table-admin-css', | |
| 112 | - $this->fileManager->locateAsset( 'admin/style.css' ), | |
| 113 | - null, | |
| 114 | - TierPricingTablePlugin::VERSION | |
| 115 | - ); | |
| 116 | - } | |
| 117 | - | |
| 118 | - } | |
| 119 | - | |
| 120 | -} | |
| 17 | +class Admin { | |
| 18 | + | |
| 19 | + use ServiceContainerTrait; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * Array of Managers | |
| 23 | + * | |
| 24 | + * @var array | |
| 25 | + */ | |
| 26 | + private $managers; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Admin constructor. | |
| 30 | + * | |
| 31 | + * Register menu items and handlers | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + public function __construct() { | |
| 35 | + new Product(); | |
| 36 | + new TieredPricingTab(); | |
| 37 | + new RoleCustomerPricingTab(); | |
| 38 | + new AdvanceOptionsForVariableProduct(); | |
| 39 | + new TipsManager(); | |
| 40 | + | |
| 41 | + new WelcomePage(); | |
| 42 | + | |
| 43 | + add_action( 'admin_enqueue_scripts', [ $this, 'enqueueAssets' ], 10, 2 ); | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Register assets on product create/update page | |
| 48 | + */ | |
| 49 | + public function enqueueAssets() { | |
| 50 | + wp_enqueue_script( 'tiered-pricing-table-admin-js', | |
| 51 | + $this->getContainer()->getFileManager()->locateJSAsset( 'admin/main' ), [ 'jquery' ], | |
| 52 | + TierPricingTablePlugin::VERSION ); | |
| 53 | + wp_enqueue_style( 'tiered-pricing-table-admin-css', | |
| 54 | + $this->getContainer()->getFileManager()->locateCSSAsset( 'admin/style.css' ), array(), | |
| 55 | + TierPricingTablePlugin::VERSION ); | |
| 56 | + } | |
| 57 | +} | |