PluginProbe
Tiered Pricing Table for WooCommerce / 2.0
Tiered Pricing Table for WooCommerce v2.0
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
← All changes | src/Admin/Admin.php +101 -50 trunk2.0 View file →
@@ -1,57 +1,108 @@
1 -<?php namespace TierPricingTable\Admin;
1 +<?php
2 2
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;
3 +namespace TierPricingTable\Admin;
11 4
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 ;
12 11 /**
13 12 * Class Admin
14 13 *
15 14 * @package TierPricingTable\Admin
16 15 */
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 -}
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 +}