Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2011
    Posts
    168
    Plugin Contributions
    0

    Default How to access the backend setting form a file in root

    the code as:
    require(DIR_WS_CLASSES . 'shipping.php');
    $shipping_modules = new shipping;
    $quotes = $shipping_modules->quote();

    If I put the code in a file that localizes in modules fold, it works well. When I dump the $GLOBALS[$include_modules[$i]['class']] from the includes\classes\shipping.php(line 65), the output is as class zones#151 (9) { public $code => ....public $enabled => bool(true) .....} .

    If I put the code in a file that localizes in root fold, it doesn't work. And when dumping the $GLOBALS[$include_modules[$i]['class']] , the output is as class zones#151 (9) { public $code => ....public $enabled => NULL .....}. It looks like it is fail to access the backend setting. The file in root fold had included "includes/application_top.php" and "includes/classes/http_client.php". Do I miss other files which need to be included? Or the setting data must be assecced from the includes fold.?

  2. #2
    Join Date
    Jan 2004
    Posts
    66,380
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to access the backend setting form a file in root

    The context is important, but you're avoiding that in your posts.
    Please explain WHY you're doing this.

    What is the javascript activity you're doing, and why?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Oct 2011
    Posts
    168
    Plugin Contributions
    0

    Default Re: How to access the backend setting form a file in root

    Quote Originally Posted by DrByte View Post
    The context is important, but you're avoiding that in your posts.
    Please explain WHY you're doing this.

    What is the javascript activity you're doing, and why?
    For adding a shipping estimate on product_info page, I create a new file as modules\shipping_estimator_Pinfo.php which modified from shipping_estimator.php
    Code:
    if (!defined('IS_ADMIN_FLAG')) {
      die('Illegal Access');
    }
    
    if ($current_page_base != 'popup_shipping_estimator') {
      require(DIR_WS_MODULES . '/pages/popup_shipping_estimator/jscript_addr_pulldowns.php');
    }
    ?>
    
    <script language="javascript" type="text/javascript">
    function estimat_submit(){
      document.cart_quantity.action = this.location.href; 
      update_zone(this.form);
      document.cart_quantity.submit();
      return false;
    }
    </script>
    
    <?php
      require_once('includes/classes/http_client.php'); 
    $selected_country = "";
    if(isset($_POST['zone_country_id'])){
    	$selected_country = $_POST['zone_country_id'];
    	$_SESSION['customer_selected_country']= $_POST['zone_country_id'];
    }elseif($_SESSION['customer_selected_country']){
    	$selected_country = $_SESSION['customer_selected_country'];
    }elseif ($_SESSION['customer_country_id']) {
    	$selected_country = $_SESSION['customer_country_id'];		
    }
    
      require(DIR_WS_CLASSES . 'shipping.php');
      $shipping_modules = new shipping;
      $quotes = $shipping_modules->quote();
    
    /** followed by the code to show the estimation result**/
    That code will be call in the tpl_product_info_display.php and it is work. Now, I am trying to use ajax to update the estimation part only. I created a file with the same name as "shipping_estimator_Pinfo.php" in root fold.
    Code:
    <?php 
    require_once('/vendor/autoload.php'); 
    require ('includes/application_top.php');
    require_once('includes/classes/http_client.php'); // shipping in basket
    
    $language_page_directory = DIR_WS_LANGUAGES.$_SESSION['language'].'/';
    $selected_country = "";
    if(isset($_POST['zone_country_id'])){
    	$selected_country = $_POST['zone_country_id'];
    	$_SESSION['customer_selected_country']= $_POST['zone_country_id'];
    }elseif($_SESSION['customer_selected_country']){
    	$selected_country = $_SESSION['customer_selected_country'];
    }elseif ($_SESSION['customer_country_id']) {
    	$selected_country = $_SESSION['customer_country_id'];		
    }
    
      // weight and count needed for shipping !
      require(DIR_WS_CLASSES . 'shipping.php');
      $shipping_modules = new shipping;
      $quotes = $shipping_modules->quote();
    
    /** followed code to handle the $quotes **/
    in the modules\shipping_estimator_Pinfo.php I modified the js code as
    Code:
    $(document).ready(function(){
    	$("#country").change(function(){
    		$.ajax({ 
    		 type: "POST", 	
    			url: "shipping_estimator_Pinfo.php",
    			data: {
    				zone_country_id: $(this).children('option:selected').val(), 
    				cart_quantity: $("input[name='cart_quantity']").val(),
    				products_id: <?php echo $_GET["products_id"];?>
    			},
    			dataType: "json",
    			success: function(data){
    				if (data.success) { 
    					$("#createResult").html(data.msg);
    				} else {
    					$("#createResult").html("error:" + data.msg);
    				} 
    			},
    			error: function(jqXHR){ 
    			 alert("error:" + jqXHR.status); 
    			}, 
    		});
    	});
    });

  4. #4
    Join Date
    Jan 2004
    Posts
    66,380
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to access the backend setting form a file in root

    1. Are you intending this to give a shipping quote for the specific *product*? Or for everything that's in the shopping cart?

    2. Which shipping modules do you have installed and enabled in your store?

    3. Why are you running vendor/autoload.php?

    4. Inside shipping_estimator_Pinfo.php what does it tell you is the value of $_SESSION['customer_id'] and $_SESSION['language'] ?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Oct 2011
    Posts
    168
    Plugin Contributions
    0

    Default Re: How to access the backend setting form a file in root

    Quote Originally Posted by DrByte View Post
    1. Are you intending this to give a shipping quote for the specific *product*? Or for everything that's in the shopping cart?

    2. Which shipping modules do you have installed and enabled in your store?

    3. Why are you running vendor/autoload.php?

    4. Inside shipping_estimator_Pinfo.php what does it tell you is the value of $_SESSION['customer_id'] and $_SESSION['language'] ?
    1. The purpose is to give the shipping estimation for this product show on the current page for everybody including unregistered visitors. It hasn't relation with the shopping cart.

    2. Only the zone module is enabled. (disable other modules that installed by default.)

    3. I had added the mobile detection in init_templates.php. So, without the vendor/autoload.php, the server will throw out a 500 error.

    4. There isn't the value of $_SESSION['customer_id'], and $_SESSION['language'] is "english".

  6. #6
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: How to access the backend setting form a file in root

    Quote Originally Posted by su35 View Post
    1. The purpose is to give the shipping estimation for this product show on the current page for everybody including unregistered visitors.
    So you have the same shipping cost regardless whether the product is to be shipped locally, interstate or overseas? If this is the case, you are probably making the task a lot harder than it needs to be. Im pretty sure that zencart has a method of setting a shipping cost per item based on a price being entered into the product weight field, so it should be trivial to display that on the products page (as opposed to having to use ajax and some other shipping module).

    Just a passing thought.
    Cheers
    RodG

  7. #7
    Join Date
    Oct 2011
    Posts
    168
    Plugin Contributions
    0

    Default Re: How to access the backend setting form a file in root

    Quote Originally Posted by RodG View Post
    So you have the same shipping cost regardless whether the product is to be shipped locally, interstate or overseas? If this is the case, you are probably making the task a lot harder than it needs to be. Im pretty sure that zencart has a method of setting a shipping cost per item based on a price being entered into the product weight field, so it should be trivial to display that on the products page (as opposed to having to use ajax and some other shipping module).

    Just a passing thought.
    Cheers
    RodG
    I am test the code on local. For simplification, there is just one module be actived.

 

 

Similar Threads

  1. v153 Add custom form submission data access on Admin backend
    By fahadali in forum Customization from the Admin
    Replies: 9
    Last Post: 12 Feb 2016, 02:59 AM
  2. Replies: 23
    Last Post: 8 Oct 2014, 05:32 AM
  3. Setting up downloads Above the Root folder
    By dharrison in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 22 Jul 2011, 02:29 PM
  4. how to access the variables in an external linked file?
    By robear in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 20 May 2008, 05:58 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR