Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21
  1. #11
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: shopping_cart logic - Help please

    Thanks Clyde, i'll take a look at that.

    Dr Byte, useful information from you yet again. Thanks for the pointers.


    Steve

  2. #12
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: shopping_cart logic - Help please

    Dr Byte...

    The section of code below is requiring information from a new sql query that would be placed in the main_template_vars file, and also information from a query that is being made in the header_php.php file. What is the best solution to get around this issue?? Run the required sql query again in main_template_vars, or is there a way that data can be passed from header_php to main_template_vars?
    Code:
     if ($gift_exists == 0){
    	   if ($products[$i]->fields['id'] == $gift->fields['products_id']) { // gift already in cart
     		$gift_exists = $products[$i]->fields['id'];
     		$gift_price = $gifts->fields['products_price'];
    		$deficit = $gift->fields['threshold'] - $num_in_cart + $gift_price;
    	      break;
              } else {
    	      $deficit = $gift->fields['threshold'] - $num_in_cart;
            }
    	 
          } else {
     	 $deficit = $gift->fields['threshold'] - $num_in_cart + $gift_price;	
         }
     $gift->MoveNext();
    Thanks
    Steve

  3. #13
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: shopping_cart logic - Help please

    Once you loop through the results of a query, you have to re-run that query to loop through its content again.

    If the variables set in header_php.php already contain the information you need, you can still reference them in main_template_vars.php, as they well already be set and available.
    .

    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.

  4. #14
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: shopping_cart logic - Help please

    Ok. I understand what you're saying there. What i don't yet understand is in which order is the code processed? Does it call header_php.php before it calls main_template_vars.php
    As an example, if i have a new query that takes data from a table to see what has been set as a free gift, it then has to check to see if any of the products in the cart are the free gift. How can ensure that it has already run the query to get the data on what is in the cart, before it runs the query to check against the list of gifts available?

    Thanks
    Steve

  5. #15
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: shopping_cart logic - Help please

    header_php.php runs first, followed by main_template_vars.php when the template section is executed.

    http://www.zen-cart.com/index.php?ma...roducts_id=378
    .

    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.

  6. #16
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: shopping_cart logic - Help please

    Oh drat...that throws my theory of why i can't get the results i want out of the window.
    Using this code:
    Code:
     $num_in_cart  = $currencies->format($_SESSION['cart']->show_total());
     $products = $_SESSION['cart']->get_products();
       
     $gift =  $db->Execute("SELECT fg.*, p.products_id, p.products_model, p.products_price, p.products_image, p.products_status, pd.products_name FROM " . TABLE_CARROT . " fg, " . TABLE_PRODUCTS . " p
        LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON (pd.products_id=fg.products_id)
        WHERE pd.language_id = '" . (int)$_SESSION['languages_id'] . "' AND p.products_id = fg.products_id AND p.products_status = '1' ORDER BY fg.threshold ASC");
    	$threshold = 0;
        $p=0;
        $gift_price=0;
        $gift_exists=0;
    	   while (!$gift->EOF) {  // loop through the current gifts
           if ($gift_exists == 0){
    	   if ($products[$i]->fields['id'] == $gift->fields['products_id']) { // gift already in cart
     		$gift_exists = $products[$i]->fields['id'];
     		$gift_price = $gift->fields['products_price'];
    		$deficit = $gift->fields['threshold'] - $num_in_cart + $gift_price;
    	      break;
              } else {
    	      $deficit = $gift->fields['threshold'] - $num_in_cart;
            }
    	 
          } else {
     	 $deficit = $gift->fields['threshold'] - $num_in_cart + $gift_price;	
         }
     $gift->MoveNext();
     if ( $deficit < 20 && $deficit > 0 ) {
     	$near_limit = 1;
          } else {
     	$near_limit = 0;
          }
    		
          if ($num_in_cart >= $gift->fields['threshold'] && $deficit <= 0) { 
                      // cart could qualify for this gift
    			// check to see if in cart already
    			// add to gift list if not in cart
     	 if ($gift['products_id'] != $gift_exists && $deficit <= 0) { // this particular gift is not in cart but qualifies
     		$freebie[$p]['message'] .= sprintf(TEXT_QUALIFIED_FOR_GIFT, $currencies->display_price($gift->fields['threshold'],zen_get_tax_rate($gift['products_tax_class_id'])));
         $freebie[$p]['link'] = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $gift->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"' . $gift->fields['products_id'] ) . '</a>';
     		$freebie[$p]['name']    		= $gift->fields['products_name'];
     		$freebie[$p]['id']      		= $gift->fields['products_id'];
     		$freebie[$p]['image']   		= $gift->fields['products_image'];
    		$p++;
     	 
    	 } else if ($near_limit) {
     	 if ($gift->fields['products_id'] != $gift_exists) { // this particular gift is not in cart
    		$freebie[$p]['message'] .= sprintf(TEXT_CLOSE_TO_FREE_GIFT, $currencies->display_price($deficit,tep_get_tax_rate($gift['products_tax_class_id'])));
     		$freebie[$p]['link'] = '';
     		$freebie[$p]['name']    		= $gift->fields['products_name'];
     		$freebie[$p]['id']      		= $gift->fields['products_id'];
     		$freebie[$p]['image']   		= $gift->fields['products_image'];
    		$p++;
     	 } else {
    	   	  // cart cannot qualify for this gift
    		  // remove if in cart
     		$cart->remove($gift->fields['products_id']);
     	 }
    	       } else {
    		 // cart cannot qualify for this gift
    		 // remove if in cart
     	      $cart->remove($gift->fields['products_id']);
         }
     	 $threshold = $gift->fields['threshold'];
         }
     }
    I am not getting the results i expect. If i echo any of the variables that are from the sql query written then i get the expected output, however, if i echo any output that combines $products[$i] which appears to be called in the header_php, then i don't get any output. I'm checking all my syntax in case i've written in an error, but thus far i havn't spotted anything obvious.

    Can you see anything wrong in the above code?

    Thanks
    Steve

  7. #17
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: shopping_cart logic - Help please

    I'm not sure why your $gift->MoveNext() was in the middle of the while loop instead of at the end. Running that function changes the pointer of which $gift record you're pointing at, causing all the code below it to refer to the "next" record instead of the current one used in the first half.

    Additionally, you're not even using the $products variable ... or rather, you were trying to use it, but using $products[$i] without looping through all the available iterations of $i when using it will leave you comparing wrong data with wrong data, and getting results you don't want or expect.

    I've not tested the following, but I propose these changes may be a little closer to what you need:
    Code:
    $num_in_cart  = $currencies->format($_SESSION['cart']->show_total());
    $products = $_SESSION['cart']->get_products();
    
    $gift =  $db->Execute("SELECT fg.*, p.products_id, p.products_model, p.products_price, p.products_image, p.products_status, pd.products_name FROM " . TABLE_CARROT . " fg, " . TABLE_PRODUCTS . " p
                           LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON (pd.products_id=fg.products_id)
                           WHERE pd.language_id = '" . (int)$_SESSION['languages_id'] . "' AND p.products_id = fg.products_id AND p.products_status = '1' ORDER BY fg.threshold ASC");
    $threshold = 0;
    $p=0;
    $gift_price=0;
    $gift_exists=0;
    while (!$gift->EOF) {  // loop through the current gifts
      if ($gift_exists == 0){
        if ($_SESSION['cart']->in_cart($gift->fields['products_id'])) { // gift already in cart
          $gift_exists = $gift->fields['products_id'];
          $gift_price = $gift->fields['products_price'];
          $deficit = $gift->fields['threshold'] - $num_in_cart + $gift_price;
          break;
        } else {
          $deficit = $gift->fields['threshold'] - $num_in_cart;
        }
    
      } else {
        $deficit = $gift->fields['threshold'] - $num_in_cart + $gift_price;
      }
      if ( $deficit < 20 && $deficit > 0 ) {
        $near_limit = 1;
      } else {
        $near_limit = 0;
      }
    
      if ($num_in_cart >= $gift->fields['threshold'] && $deficit <= 0) {
        // cart could qualify for this gift
        // check to see if in cart already
        // add to gift list if not in cart
        if ($gift['products_id'] != $gift_exists && $deficit <= 0) { // this particular gift is not in cart but qualifies
          $freebie[$p]['message'] .= sprintf(TEXT_QUALIFIED_FOR_GIFT, $currencies->display_price($gift->fields['threshold'],zen_get_tax_rate($gift['products_tax_class_id'])));
          $freebie[$p]['link'] = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $gift->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"' . $gift->fields['products_id'] ) . '</a>';
          $freebie[$p]['name']    		= $gift->fields['products_name'];
          $freebie[$p]['id']      		= $gift->fields['products_id'];
          $freebie[$p]['image']   		= $gift->fields['products_image'];
          $p++;
    
        } else if ($near_limit) {
          if ($gift->fields['products_id'] != $gift_exists) { // this particular gift is not in cart
            $freebie[$p]['message'] .= sprintf(TEXT_CLOSE_TO_FREE_GIFT, $currencies->display_price($deficit,tep_get_tax_rate($gift['products_tax_class_id'])));
            $freebie[$p]['link'] = '';
            $freebie[$p]['name']    		= $gift->fields['products_name'];
            $freebie[$p]['id']      		= $gift->fields['products_id'];
            $freebie[$p]['image']   		= $gift->fields['products_image'];
            $p++;
          } else {
            // cart cannot qualify for this gift
            // remove if in cart
            $cart->remove($gift->fields['products_id']);
          }
        } else {
          // cart cannot qualify for this gift
          // remove if in cart
          $cart->remove($gift->fields['products_id']);
        }
        $threshold = $gift->fields['threshold'];
      }
      $gift->MoveNext();
    }
    .

    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.

  8. #18
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: shopping_cart logic - Help please

    Quote Originally Posted by DrByte View Post
    I'm not sure why your $gift->MoveNext() was in the middle of the while loop instead of at the end.

    That was an error on my part during the conversion from OSC structure.. oops.

    The changes you suggested worked fine, and the correct results are now accessible . I have another stumbling block that i'm struggling with.
    The module adds a field to TABLE_PRODUCTS which is called product_carrot. This is set to either 1 or 0 by a switch in the admin section.
    Part of the OSC code in shopping_cart is
    Code:
    if ($products[$i]['carrot'] == "1"){
        			$products_name = '<table border="0" cellspacing="2" cellpadding="2">' .
    		'  <tr>' .
    		'    <td class="productListing-data" align="center">' . tep_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</td>' .
    		'    <td class="productListing-data" valign="top"><b>' . $products[$i]['name'] . '</b>';
    	}
    	else{
    		$products_name = '<table border="0" cellspacing="2" cellpadding="2">' .
                 	'  <tr>' .
                 	'    <td class="productListing-data" align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">' . tep_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>' .
                 	'    <td class="productListing-data" valign="top"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '"><b>' . $products[$i]['name'] . '</b></a>';
    
    	}
    Changing this to suit ZC hasn't been a problem, except that if i echo $products[$i]['carrot'] to check the variable is filled, then i get no output. This leads me to believe that the contents of the field products_carrot is not being read from the db.
    What i need to do is ensure that the products_carrot field from TABLE_PRODUCTS is passed to the shopping cart along with the rest of the data.

    Any help greatly appreciated.

    Thanks
    Steve

  9. #19
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: shopping_cart logic - Help please

    Quote Originally Posted by strelitzia View Post
    Changing this to suit ZC hasn't been a problem, except that if i echo $products[$i]['carrot'] to check the variable is filled, then i get no output. This leads me to believe that the contents of the field products_carrot is not being read from the db.
    What i need to do is ensure that the products_carrot field from TABLE_PRODUCTS is passed to the shopping cart along with the rest of the data.
    You'll have to add the additional field to the query in the shopping_cart class on line 1054 (circa v1.3.7.1) and also to the array built on line 1176.
    .

    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.

  10. #20
    Join Date
    Nov 2005
    Location
    France
    Posts
    582
    Plugin Contributions
    8

    Default Re: shopping_cart logic - Help please

    Quote Originally Posted by DrByte View Post
    You'll have to add the additional field to the query in the shopping_cart class on line 1054 (circa v1.3.7.1) and also to the array built on line 1176.
    That's where i went wrong. I'd added the additional field to the query, but forgot to add it to the array! Beginners mistake and lack of true understanding there i fear!

    I have another point that i could do with some advice on.

    The original OSC shopping_cart.php file has three sections of code added to make the mod work. The first section is processed before any of the original code is processed, and this is now in my new main_template_vars.php file. The two remaining sections of mod code are run after some of the original code has been processed. Now, where i'm a bit stuck is knowing how i can get this code to be processed at the correct moment if it is in main_template_vars.php and not placed after the relevant code section in tpl_shopping_cart_default.php.

    I'm trying to avoid making any changes to the tpl_shopping_cart_default.php and header_php.php files unless strictly necessary as i realise this impacts greatly on ease of future upgrades.

    Thanks
    Steve

 

 
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Need help for bestsellers logic
    By lindanewbie in forum Basic Configuration
    Replies: 0
    Last Post: 24 Mar 2011, 01:52 AM
  2. Please help me with Page Layout Logic?
    By zenHomeboy in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 6 Aug 2010, 05:31 PM
  3. Help With Inputting Shipping Logic
    By lmw1 in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 7 Jun 2009, 02:45 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