Sindbad~EG File Manager

Current Path : /home/nicedoo/www/wp-content/plugins/tier-pricing-table/src/Admin/ProductPage/
Upload File :
Current File : /home/nicedoo/www/wp-content/plugins/tier-pricing-table/src/Admin/ProductPage/TieredPricingTab.php

<?php

namespace TierPricingTable\Admin\ProductPage;

use  TierPricingTable\Core\ServiceContainerTrait ;
use  TierPricingTable\PriceManager ;
use  TierPricingTable\Forms\MinimumOrderQuantityForm ;
use  TierPricingTable\Forms\TieredPricingRulesForm ;
/**
 * Class ProductManager
 *
 * @package TierPricingTable\Admin\Product
 */
class TieredPricingTab
{
    use  ServiceContainerTrait ;
    public function __construct()
    {
        // Tiered Pricing Product Tab
        add_filter(
            'woocommerce_product_data_tabs',
            array( $this, 'register' ),
            99,
            1
        );
        add_action( 'woocommerce_product_data_panels', array( $this, 'render' ) );
        add_action( 'woocommerce_process_product_meta', array( $this, 'save' ) );
    }
    
    /**
     * Add tiered pricing tab to woocommerce product tabs
     *
     * @param  array  $productTabs
     *
     * @return array
     */
    public function register( $productTabs )
    {
        $productTabs['tiered-pricing-tab'] = array(
            'label'  => __( 'Tiered Pricing', 'tier-pricing-table' ),
            'target' => 'tiered-pricing-data',
            'class'  => array( 'show_if_simple', 'show_if_variable' ),
        );
        return $productTabs;
    }
    
    /**
     * Render content for the tiered pricing tab
     */
    public function render()
    {
        global  $post ;
        ?>
		<div id="tiered-pricing-data" class="panel woocommerce_options_panel">
			<?php 
        if ( !tpt_fs()->is_premium() ) {
            $this->renderUpgradeNotice();
        }
        do_action( 'tiered_pricing_table/admin/pricing_tab_begin', $post->ID );
        $min = PriceManager::getProductQtyMin( $post->ID, 'edit' );
        MinimumOrderQuantityForm::render( null, null, $min );
        do_action( 'tiered_pricing_table/admin/after_minimum_order_quantity_field', $post->ID, null );
        ?>
			
			<div class="hidden show_if_variable">
				<?php 
        $type = PriceManager::getPricingType( $post->ID, 'fixed', 'edit' );
        $percentageRules = PriceManager::getPercentagePriceRules( $post->ID, 'edit' );
        $fixedRules = PriceManager::getFixedPriceRules( $post->ID, 'edit' );
        TieredPricingRulesForm::render(
            $post->ID,
            null,
            null,
            $type,
            $percentageRules,
            $fixedRules,
            '_variable'
        );
        ?>
			</div>
			
			<?php 
        do_action( 'tiered_pricing_table/admin/before_advance_product_options', $post->ID );
        ?>
			
			<div class="tiered_pricing_tab_product_advance_options">
				<div class="tiered_pricing_tab_product_advance_options__header">
					<h4>
						<?php 
        esc_html_e( 'Advanced options', 'tier-pricing-table' );
        ?>
					</h4>
					<div>
						<span class="tiered_pricing_arrow_down">▼</span>
						<span class="tiered_pricing_arrow_up">▲</span>
					</div>
				</div>
				
				<div class="tiered_pricing_tab_product_advance_options__content">
					
					<?php 
        woocommerce_wp_select( array(
            'id'          => '_tiered_pricing_template',
            'value'       => self::getProductTemplate( $post->ID ),
            'options'     => array(
            'default'          => __( 'Default', 'tier-pricing-table' ),
            'table'            => __( 'Table', 'tier-pricing-table' ),
            'blocks'           => __( 'Blocks', 'tier-pricing-table' ),
            'options'          => __( 'Options', 'tier-pricing-table' ),
            'dropdown'         => __( 'Dropdown', 'tier-pricing-table' ),
            'horizontal-table' => __( 'Horizontal Table', 'tier-pricing-table' ),
            'tooltip'          => __( 'Tooltip', 'tier-pricing-table' ),
        ),
            'label'       => __( 'Display as (layout)', 'tier-pricing-table' ),
            'description' => __( 'Specify a tiered pricing layout for the product. Leave the default to use the layout from the settings', 'tier-pricing-table' ),
            'default'     => 'default',
            'desc_tip'    => true,
        ) );
        ?>
					
					<p class="form-field">
						<label>
							<?php 
        esc_html_e( 'Base unit name', 'tier-pricing-table' );
        ?>
						</label>
						
						<?php 
        $productBaseUnitName = self::getProductBaseUnitName( $post->ID );
        ?>
						
						<input type="text"
							   value="<?php 
        echo  esc_attr( $productBaseUnitName['singular'] ) ;
        ?>"
							   placeholder="<?php 
        esc_attr_e( 'Singular (e.g. piece)', 'tier-pricing-table' );
        ?>"
							   style="width: 24%; margin-right: 20px;"
							   name="_tiered_pricing_base_unit_name[singular]">
						
						<input type="text"
							   value="<?php 
        echo  esc_attr( $productBaseUnitName['plural'] ) ;
        ?>"
							   placeholder="<?php 
        esc_attr_e( 'Plural (e.g. pieces)', 'tier-pricing-table' );
        ?>"
							   style="width: 24%"
							   name="_tiered_pricing_base_unit_name[plural]">
					</p>
					
					<div style="padding: 0 20px 10px 162px; margin-bottom: 10px">
						<?php 
        esc_html_e( 'For example: pieces, boxes, bottles, packs, etc. It will be shown next to quantities. Leave empty to use global settings.', 'tier-pricing-table' );
        ?>
					</div>
					
					<?php 
        do_action( 'tiered_pricing_table/admin/advance_product_options', $post->ID );
        ?>
				</div>
			</div>
			
			<?php 
        do_action( 'tiered_pricing_table/admin/pricing_tab_end', $post->ID );
        ?>
		</div>
		<?php 
    }
    
    protected function renderUpgradeNotice()
    {
        ?>
		<div
			style="background: #fafafa; padding: 15px 10px; margin: 0 0 20px;border-bottom: 1px solid #eee; font-size: .9em;">
			<span style="color: red;">
			<?php 
        esc_html_e( 'Minimum order quantity and role-based rules are available in the premium version.', 'tier-pricing-table' );
        ?>
					<a target="_blank" href="<?php 
        echo  esc_attr( tpt_fs()->get_upgrade_url() ) ;
        ?>">
						<?php 
        esc_html_e( 'Upgrade you plan', 'tier-pricing-table' );
        ?>
					</a>
			</span>
		</div>
		<?php 
    }
    
    /**
     * Save tiered pricing tab data
     *
     * @param  $productId
     */
    public function save( $productId )
    {
        if ( wp_verify_nonce( true, true ) ) {
            // as phpcs comments at Woo is not available, we have to do such a trash
            $woo = 'Woo, please add ignoring comments to your phpcs checker';
        }
        $template = ( isset( $_POST['_tiered_pricing_template'] ) ? sanitize_text_field( $_POST['_tiered_pricing_template'] ) : 'default' );
        self::updateProductTemplate( $productId, sanitize_text_field( $template ) );
        $baseUnitName = ( isset( $_POST['_tiered_pricing_base_unit_name'] ) ? array_map( 'sanitize_text_field', $_POST['_tiered_pricing_base_unit_name'] ) : array() );
        self::updateProductBaseUnitName( $productId, $baseUnitName );
    }
    
    public static function getProductTemplate( $productId )
    {
        $template = get_post_meta( $productId, '_tiered_pricing_template', true );
        return ( in_array( $template, array(
            'default',
            'table',
            'blocks',
            'dropdown',
            'tooltip',
            'options'
        ) ) ? $template : 'default' );
    }
    
    public static function updateProductTemplate( $productId, $template )
    {
        $template = ( in_array( $template, array(
            'table',
            'blocks',
            'dropdown',
            'tooltip',
            'options'
        ) ) ? $template : 'default' );
        
        if ( 'default' !== $template ) {
            update_post_meta( $productId, '_tiered_pricing_template', $template );
        } else {
            delete_post_meta( $productId, '_tiered_pricing_template' );
        }
    
    }
    
    public static function getProductBaseUnitName( $productId ) : array
    {
        $_baseUnitName = (array) get_post_meta( $productId, '_tiered_pricing_base_unit_name', true );
        $baseUnitName['singular'] = $_baseUnitName['singular'] ?? null;
        $baseUnitName['plural'] = $_baseUnitName['plural'] ?? null;
        return $baseUnitName;
    }
    
    public static function updateProductBaseUnitName( $productId, array $unitNames )
    {
        $baseUnitName['singular'] = $unitNames['singular'] ?? null;
        $baseUnitName['plural'] = $unitNames['plural'] ?? null;
        
        if ( empty($baseUnitName['singular']) && empty($baseUnitName['plural']) ) {
            delete_post_meta( $productId, '_tiered_pricing_base_unit_name' );
        } else {
            update_post_meta( $productId, '_tiered_pricing_base_unit_name', $baseUnitName );
        }
    
    }

}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists