| @@ -1,108 +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 Premmerce\SDK\V2\FileManager\FileManager ; | |
| 6 | -use TierPricingTable\Admin\ProductManagers\SimpleProductManager ; | |
| 7 | -use TierPricingTable\Admin\ProductManagers\VariationProductManager ; | |
| 8 | -use TierPricingTable\Freemius ; | |
| 9 | -use TierPricingTable\Settings\Settings ; | |
| 10 | -use TierPricingTable\TierPricingTablePlugin ; | |
| 11 | 12 | /** |
| 12 | 13 | * Class Admin |
| 13 | 14 | * |
| 14 | 15 | * @package TierPricingTable\Admin |
| 15 | 16 | */ |
| 16 | -class Admin | |
| 17 | -{ | |
| 18 | - /** | |
| 19 | - * @var FileManager | |
| 20 | - */ | |
| 21 | - private $fileManager ; | |
| 22 | - /** | |
| 23 | - * @var Settings | |
| 24 | - */ | |
| 25 | - private $settings ; | |
| 26 | - /** | |
| 27 | - * @var array | |
| 28 | - */ | |
| 29 | - private $managers ; | |
| 30 | - /** | |
| 31 | - * @var Freemius | |
| 32 | - */ | |
| 33 | - private $licence ; | |
| 34 | - /** | |
| 35 | - * Admin constructor. | |
| 36 | - * | |
| 37 | - * Register menu items and handlers | |
| 38 | - * | |
| 39 | - * @param FileManager $fileManager | |
| 40 | - * @param Freemius $licence | |
| 41 | - * @param Settings $settings | |
| 42 | - */ | |
| 43 | - public function __construct( FileManager $fileManager, Freemius $licence, Settings $settings ) | |
| 44 | - { | |
| 45 | - $this->fileManager = $fileManager; | |
| 46 | - $this->settings = $settings; | |
| 47 | - $this->licence = $licence; | |
| 48 | - $this->initManagers(); | |
| 49 | - add_action( 'admin_enqueue_scripts', [ $this, 'enqueueAssets' ] ); | |
| 50 | - if ( get_transient( 'tier_pricing_table_activated' ) ) { | |
| 51 | - add_action( 'admin_notices', [ $this, 'showActivationMessage' ] ); | |
| 52 | - } | |
| 53 | - if ( $this->licence->isFree() ) { | |
| 54 | - add_action( 'woocommerce_settings_' . Settings::SETTINGS_PAGE, function () { | |
| 55 | - $this->fileManager->includeTemplate( 'admin/upgrade-message.php', [ | |
| 56 | - 'upgradeLink' => $this->licence->getUpgradeLink(), | |
| 57 | - ] ); | |
| 58 | - } ); | |
| 59 | - } | |
| 60 | - } | |
| 61 | - | |
| 62 | - public function initManagers() | |
| 63 | - { | |
| 64 | - $this->managers = [ | |
| 65 | - SimpleProductManager::class => new SimpleProductManager( $this->fileManager, $this->settings, $this->licence ), | |
| 66 | - VariationProductManager::class => new VariationProductManager( $this->fileManager, $this->settings, $this->licence ), | |
| 67 | - ]; | |
| 68 | - } | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * Show message about activation plugin and advise next step | |
| 72 | - */ | |
| 73 | - public function showActivationMessage() | |
| 74 | - { | |
| 75 | - $link = $this->settings->getLink(); | |
| 76 | - $this->fileManager->includeTemplate( 'admin/activation-message.php', [ | |
| 77 | - 'link' => $link, | |
| 78 | - ] ); | |
| 79 | - delete_transient( 'tiered_pricing_table_activated' ); | |
| 80 | - } | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * Register assets on product create/update page | |
| 84 | - * | |
| 85 | - * @param $page | |
| 86 | - */ | |
| 87 | - public function enqueueAssets( $page ) | |
| 88 | - { | |
| 89 | - global $post ; | |
| 90 | - | |
| 91 | - if ( ($page == 'post.php' || ($page = 'post_new.php')) && $post && $post->post_type == 'product' ) { | |
| 92 | - wp_enqueue_script( | |
| 93 | - 'tier-pricing-table-admin-js', | |
| 94 | - $this->fileManager->locateAsset( 'admin/main.js' ), | |
| 95 | - 'jquery', | |
| 96 | - TierPricingTablePlugin::VERSION | |
| 97 | - ); | |
| 98 | - wp_enqueue_style( | |
| 99 | - 'tier-pricing-table-admin-css', | |
| 100 | - $this->fileManager->locateAsset( 'admin/style.css' ), | |
| 101 | - null, | |
| 102 | - TierPricingTablePlugin::VERSION | |
| 103 | - ); | |
| 104 | - } | |
| 105 | - | |
| 106 | - } | |
| 107 | - | |
| 108 | -} | |
| 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 | +} | |