Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2013
    Posts
    706
    Plugin Contributions
    0

    Default custom code not fully working

    zen 1.56c and php7.0
    i have this custom code that only show certain options based on selection.
    Code:
    <td colspan="2">
                                    <fieldset class="AdvancedShipperMethod<?php echo ((($method_num + 1) % 2 == 0) ? 'Odd' : 'Even') .
    					'AvailabilityScheduling'; ?>">
    					<legend><?php echo TEXT_METHOD_AVAILABILITY_SCHEDULING; ?></legend>
                                        <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                            <tr><td class="AdvancedShipperConfigDesc"><b>Method Availability:</b></td><td class="AdvancedShipperConfigField">
                                                          <?php echo advshipperBuildRadioField('method_availability_stock', 0, $method_availability_stock == 0, null, 'id="method_availability_stock_always" '); ?> <label for="method_availability_stock_always"><?php echo TEXT_METHOD_AVAILABILITY_SCHEDULING_ALWAYS; ?></label>
                                                    <br /><?php echo advshipperBuildRadioField('method_availability_stock', 1, $method_availability_stock == 1, null, 'id="method_availability_stock_in"'); ?> <label for="method_availability_stock_in">Only Show In-Stock Products</label>
                                                    <br /><?php echo advshipperBuildRadioField('method_availability_stock', 2, $method_availability_stock == 2, null, 'id="method_availability_stock_off"'); ?> <label for="method_availability_stock_off">Only Show In-Stock/Non-Stock Products</label>
                                                    <br /><?php echo advshipperBuildRadioField('method_availability_stock', 3, $method_availability_stock == 3, null, 'id="method_availability_stock_offall"'); ?> <label for="method_availability_stock_offall">Only Show All Products</label>
    												<br /><?php echo advshipperBuildRadioField('method_availability_stock', 4, $method_availability_stock == 4, null, 'id="method_availability_stock_none"'); ?> <label for="method_availability_stock_none">Only Show Non-Stock Products</label>
    
                                                </td></tr>
    0 is suppose to show all products regardless of stock. - doesnt work (default way it use to work) dont need this if 3 works or vice-versa
    1 is show to only in-stock products shipping options
    2 is to show only in-stock and non-stock products shipping options
    3 is suppose to show all products shipping options regardless of stock. - doesnt work (default way it use to work)
    4 is to show only Non-stock products shipping options.
    what needs to change to make 0 or 3 work?

  2. #2
    Join Date
    Jan 2013
    Posts
    706
    Plugin Contributions
    0

    Default Re: custom code not fully working

    more code
    Code:
    // Variable holds information about the products in the order
    		$this->_products = $_SESSION['cart']->get_products();
    		$_SESSION['cart']->shopping_stock = 1;
    		$inStock = 0;
            $outStock = 0;
            $_SESSION['cart']->in_stock_products = [];
            $_SESSION['cart']->out_stock_products = [];
    		foreach ($this->_products as $product) {
    			$pid = $product["id"];
    			$qty = $product["quantity"];
    			$product_query = "select products_quantity
                              from " . TABLE_PRODUCTS . "
                              where products_id = '" . (int)$pid . "'";
          			$product = $db->Execute($product_query);
    			$quantity = $product->fields["products_quantity"];
    
    
                if ($quantity < $qty){
                    $_SESSION['cart']->shopping_stock = 2;
                    array_push($_SESSION['cart']->out_stock_products,(int)$pid);
                    $outStock = 1;
    
                }else{
                    $_SESSION['cart']->shopping_stock = 1;
                    array_push($_SESSION['cart']->in_stock_products,(int)$pid);
                    $inStock = 1;
                }
    		}
            if($outStock == 1 && $inStock == 1 && count($this->_products) > 0){
                $_SESSION['cart']->shopping_stock=3;
            }
    Code:
    if ($method_info["availability_stock"] != 0) {
                    if (
                        $_SESSION['cart']->shopping_stock == 1 &&
                        $method_info["availability_stock"] == 1
                    ) {
                        $has_rate = true;
                    }
    
                    if (
                        $_SESSION['cart']->shopping_stock == 2 &&
                        $method_info["availability_stock"] == 4
                    ) {
                        $has_rate = true;
                    }
    
                    if (
                        $_SESSION['cart']->shopping_stock == 3
                    ) {
                        $in_stock = 0;
                        foreach ($method_info['app_product_indexes'] as $product_i) {
    
                            if (in_array($this->_products[$product_i]['id'], $_SESSION['cart']->in_stock_products)) {
                                $in_stock++;
                            }
    
                        }
                        if(
                            $in_stock == count($method_info['app_product_indexes']) &&
                            $method_info["availability_stock"] == 1
                        ){
                            $has_rate = true;
                        }else if(
                            $in_stock == 0 &&
                            $method_info["availability_stock"] == 4
                        ){
                            $has_rate = true;
                        }else if(
                            $in_stock != 0 &&
                            $in_stock < count($method_info['app_product_indexes']) &&
                            $method_info["availability_stock"] == 2
                        ){
                            $has_rate = true;
                        }
                    }
                }
    Last edited by jimmie; 20 May 2020 at 03:17 AM.

  3. #3
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,119
    Plugin Contributions
    29

    Default Re: custom code not fully working

    What I would do is make it very clear what I am comparing.
    == 1 is integer
    == '1' is string
    = 0, if you are meaning false, why not put false.

    And what comes out of a query is always a string.

    Then make it all strict comparisons ===, then perhaps it will break some more to give you more clues along the way to fixing it.
    Steve
    github.com/torvista: Spanish Language Pack, Image Checker, Structured Data, BackupMySQL Admin/Auto, Product Listing Sorter, Redsys payment module...

  4. #4
    Join Date
    Jan 2013
    Posts
    706
    Plugin Contributions
    0

    Default Re: custom code not fully working

    this is the only part that does not work,
    Code:
    if (
                        $_SESSION['cart']->shopping_stock == 3
                    ) {
                        $in_stock = 0;
                        foreach ($method_info['app_product_indexes'] as $product_i) {
    
                            if (in_array($this->_products[$product_i]['id'], $_SESSION['cart']->in_stock_products)) {
                                $in_stock++;
                            }
    
                        }
    3 needs to combine 1, 2, and 4 together, how do i do this?

 

 

Similar Threads

  1. Custom code is not working in 1.5.5e
    By Prabu in forum Upgrading to 1.5.x
    Replies: 6
    Last Post: 25 Mar 2017, 11:45 AM
  2. v139h cant log in to admin and site is not fully working
    By rdsbaker in forum General Questions
    Replies: 5
    Last Post: 13 Dec 2013, 04:56 PM
  3. 301 Redirects Not Working Fully
    By Higherthan in forum General Questions
    Replies: 9
    Last Post: 3 Dec 2012, 11:05 PM
  4. Custom Code not working
    By nitesh107 in forum All Other Contributions/Addons
    Replies: 5
    Last Post: 3 Jun 2011, 06:45 PM
  5. CSS buttons not fully working for some buttons in my shopping_cart page
    By chasery in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 13 Apr 2010, 07:37 PM

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