Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Product options on products.tpl

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #11  
Old 05-08-2003, 10:04 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default

Hey, thanks for figuring out the array index I needed. Let me know if you figure out the price modification code or if you see any other flaws in my code. I may be generating more dynamic javascript functions than are necessarry to make the options work...haven't yet tried to optimize the code in any way.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #12  
Old 05-08-2003, 11:03 AM
 
ucmarty ucmarty is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 34
 

Default Price changing

Minorgod,

The price modification is working for me with the code that you gave me. I haven't made any changes besides the array change. I am however using a different products.tpl file than you. I don't think this would really affect anything. I can post my code if you want. Just let me know.

Marty
Reply With Quote
  #13  
Old 05-08-2003, 11:16 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default

Sweet...I hadn't even tried using the price modification part of the product options, but that actually makes sense now that I think about it, since the original product options code is what still gets run by all the other areas of the site. Since the prices on the products.tpl output aren't javascript-accessible in their current form, it would be a serious pain in the ass to have to modify the price display directly on the products.tpl page based on what options are chosen. Anyway, this makes me happy. Thanks for the info!
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #14  
Old 05-08-2003, 11:40 AM
 
ucmarty ucmarty is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 34
 

Default

Thanks for working with me too!

I appreciate the collaboration!
Reply With Quote
  #15  
Old 05-15-2003, 11:11 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default updated products.php page...

Below is an update to my modified customer/products.php page for displaying options on the products.tpl page.

Code:
<? /*****************************************************************************\ +-----------------------------------------------------------------------------+ | X-Cart | | Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved. | +-----------------------------------------------------------------------------+ | The Ruslan R. Fazliev forbids, under any circumstances, the unauthorized | | reproduction of software or use of illegally obtained software. Making | | illegal copies of software is prohibited. Individuals who violate copyright | | law and software licensing agreements may be subject to criminal or civil | | action by the owner of the copyright. | | | | 1. It is illegal to copy a software, and install that single program for | | simultaneous use on multiple machines. | | | | 2. Unauthorized copies of software may not be used in any way. This applies | | even though you yourself may not have made the illegal copy. | | | | 3. Purchase of the appropriate number of copies of a software is necessary | | for maintaining legal status. | | | | DISCLAIMER | | | | THIS SOFTWARE IS PROVIDED BY Ruslan R. Fazliev ``AS IS'' AND ANY | | EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL Ruslan R. Fazliev OR ITS | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | | | The Initial Developer of the Original Code is Ruslan R. Fazliev. | | Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2002 | | Ruslan R. Fazliev. All Rights Reserved. | +-----------------------------------------------------------------------------+ \*****************************************************************************/ # # $Id: products.php,v 1.30 2002/11/19 12:06:10 alfiya Exp $ # # Navigation code # $objects_per_page = $config["General"]["products_per_page"]; $total_nav_pages = ceil($current_category["product_count"]/$config["General"]["products_per_page"])+1; require "../include/navigation.php"; if($active_modules["Advanced_Statistics"]) include "../modules/Advanced_Statistics/cat_viewed.php"; # # Get products data for current category and store it into $products array # $search_query = "($sql_tbl[products].categoryid='$cat' or $sql_tbl[products].categoryid1='$cat' or $sql_tbl[products].categoryid2='$cat' or $sql_tbl[products].categoryid3='$cat') and $sql_tbl[products].forsale='Y'"; $products = func_search_products($search_query, $user_account['membership'], $first_page,$current_category["product_count"]); if (count($products) ==0) $products=""; if($active_modules["Subscriptions"]) { include "../modules/Subscriptions/subscription.php"; } // Begin Product Options Mod by Brett Brewer if(is_array($products)) foreach($products as $key=>$value){ // first we loop through the products and get their options if they have any $query="SELECT * from $sql_tbl[product_options],$sql_tbl[product_options_js] WHERE $sql_tbl[product_options].productid='$value[productid]' AND $sql_tbl[product_options_js].productid='$value[productid]'"; $products[$key]['product_options']=func_query($query); } // now we loop through the products again and parse the options if(is_array($products)) foreach($products as $key=>$value){ if(is_array($value['product_options'])) foreach($value['product_options'] as $k=>$v){ //we need to parse the options so that the template can understand them... // this is brute force value grabbing...the index 4 should be changed to a reference to an associative array index, // but I didn't see it when viewing the variables in the modified x-cart debugger window. $products[$key]['product_options'][$k]['options']=func_parse_options($v['options']); } } // now that we have all the options and the javascript code we need to parse the names of the // javascript functions and number them the same way the forms and form elements on the template will be numbered. // I'm not sure this is the best solution for this, but it was the only one I could think of. for($i=0;$i<count($products);$i++){ for($j=0;$j<count($products[$i]['product_options']);$j++){ $javascript=$products[$i]['product_options'][$j]['javascript_code']; $pattern="/product_option/i"; $replacement="product_option_".$i."_".$j; $new_javascript=preg_replace($pattern,$replacement,$javascript); $products[$i]['product_options'][$j]['javascript_code']=$new_javascript; //echo $replacement; } } //-----END Product Options Mod by Brett Brewer $smarty->assign("products",$products); $smarty->assign("navigation_script","home.php?cat=$cat"); ?>
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #16  
Old 06-18-2003, 12:19 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default Possibly a faster way to do this...

After I created the mod above, I noticed that my site was running slower and I suspected it was because the code above was looping through the products and doing a separate query for each product options and then lopping through the products again and doing a separate query for each product javascript options.

I rewrote the script so that it only does two queries, one to get all the options, and one to get all the javascript. I then loop through the products and and options and javascripts to associate the proper options and javascript with each product without doing any more MySQL queries.

In the end, I'm not sure if this way is faster since I'm now forced to loop through all the options for each product to associate them, and then loop through all the javascripts for each product to associate the correct javascript with each product. So ultimately, there's a lot more loops happening and I can't tell if I've made it faster or not. At any rate, here's the code...it still works with the modified templates posted above.

Code:
<? /*****************************************************************************\ +-----------------------------------------------------------------------------+ | X-Cart | | Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved. | +-----------------------------------------------------------------------------+ | The Ruslan R. Fazliev forbids, under any circumstances, the unauthorized | | reproduction of software or use of illegally obtained software. Making | | illegal copies of software is prohibited. Individuals who violate copyright | | law and software licensing agreements may be subject to criminal or civil | | action by the owner of the copyright. | | | | 1. It is illegal to copy a software, and install that single program for | | simultaneous use on multiple machines. | | | | 2. Unauthorized copies of software may not be used in any way. This applies | | even though you yourself may not have made the illegal copy. | | | | 3. Purchase of the appropriate number of copies of a software is necessary | | for maintaining legal status. | | | | DISCLAIMER | | | | THIS SOFTWARE IS PROVIDED BY Ruslan R. Fazliev ``AS IS'' AND ANY | | EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | DISCLAIMED. IN NO EVENT SHALL Ruslan R. Fazliev OR ITS | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | | | The Initial Developer of the Original Code is Ruslan R. Fazliev. | | Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2002 | | Ruslan R. Fazliev. All Rights Reserved. | +-----------------------------------------------------------------------------+ \*****************************************************************************/ # # $Id: products.php,v 1.30 2002/11/19 12:06:10 alfiya Exp $ # # Navigation code # $objects_per_page = $config["General"]["products_per_page"]; $total_nav_pages = ceil($current_category["product_count"]/$config["General"]["products_per_page"])+1; require "../include/navigation.php"; if($active_modules["Advanced_Statistics"]) include "../modules/Advanced_Statistics/cat_viewed.php"; //if($active_modules["Product_Options"]) // include "../modules/Product_Options/customer_options_productspage.php"; # # Get products data for current category and store it into $products array # $search_query = "($sql_tbl[products].categoryid='$cat' or $sql_tbl[products].categoryid1='$cat' or $sql_tbl[products].categoryid2='$cat' or $sql_tbl[products].categoryid3='$cat') and $sql_tbl[products].forsale='Y'"; $products = func_search_products($search_query, $user_account['membership'], $first_page,$current_category["product_count"]); if (count($products) ==0) $products=""; if($active_modules["Subscriptions"]) { include "../modules/Subscriptions/subscription.php"; } //--------Brett's Additions if($active_modules["DigitalSubscriptions"]) { include "../modules/DigitalSubscriptions/digital_subscription.php"; } //------------end Brett's Additions // Product Options Mod by Brett Brewer if(is_array($products)){ $i=0; $productcount=count($products); // first we build a query to get all the product options with a single query $query="SELECT * from $sql_tbl[product_options] WHERE "; foreach($products as $key=>$value){ $query.="productid='$value[productid]' "; if($i < $productcount-1){ $query.="OR "; } $i++; } //now get the product options $product_options=func_query($query); //now loop through the products and match each one with its corresponding options foreach($products as $key=>$product){ if(is_array($product_options)){ foreach($product_options as $options){ if($product['productid']==$options['productid']){ $products[$key]['product_options'][]=$options; } } } } // now we build a query to get all the javascript option code for the products $i=0; $query="SELECT * from $sql_tbl[product_options_js] WHERE "; foreach($products as $key=>$value){ $query.="productid='$value[productid]' "; if($i < $productcount-1){ $query.="OR "; } $i++; } //now get the js_opt_code $js_opt_code=func_query($query); //now loop through the products and associate the correct javascript code with each option. //Currently, x-cart is set up to use only one Javascript function for each product, so we will //actually be creating more javascript code than we need... foreach($products as $key=>$value){ //Make sure there are options so no errors or warnings are thrown. if(is_array($value['product_options'])){ //get the count up front so we don't waste cpu cycles on recounting at each iteration $optionscount=count($value['product_options']); for($i=0;$i<$optionscount;$i++){ //now make sure we have some js code before we try to manipulate it if(is_array($js_opt_code)){ //get the count up front so we don't waste cpu cycles on recounting at each iteration $js_optioncode_count=count($js_opt_code); //now loop through the js code and associate the correct javascript code with the correct options for($j=0;$j<$js_optioncode_count;$j++){ if($value['productid']==$js_opt_code[$j]['productid']){ $products[$key]['product_options'][$i]['javascript_code']=$js_opt_code[$j]['javascript_code']; } } } //we need to parse the options so that the template can understand them... $products[$key]['product_options'][$i]['options']=func_parse_options($products[$key]['product_options'][$i]['options']); // now that we have all the options and the javascript code we need to parse the names //of the javascript functions and number them the same way the forms and form elements //on the template will be numbered. I'm not sure this is the best solution for this, //but it was the only one I could think of. $javascript=$products[$key]['product_options'][$i]['javascript_code']; $pattern="/product_option/i"; $replacement="product_option_".$key."_".$i; $new_javascript=preg_replace($pattern,$replacement,$javascript); $products[$key]['product_options'][$i]['javascript_code']=$new_javascript; } } } } // Now, presumably, the data is correctly formatted for the template. //-----END Product Options Mod by Brett Brewer $smarty->assign("products",$products); $smarty->assign("navigation_script","home.php?cat=$cat"); ?>

If anyone knows if this is faster than the previous method, let me know please. Thanks...and...uh...you're welcome.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #17  
Old 06-30-2003, 09:08 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

Thanks Brett

If you do any more optimization, can you please keep this thread updated.

Appreciated.
Reply With Quote
  #18  
Old 06-30-2003, 10:45 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

How can we add options to the featured products page?
Reply With Quote
  #19  
Old 07-01-2003, 06:39 AM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default

Can't you just use the above example? I haven't looked at it yet, but I'll need to modify my featured products page at some point. If I do the modifications I'll post them here.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote
  #20  
Old 07-01-2003, 01:09 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default

I used the code above, but it didn't work for the featured products.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:34 AM.

   

 
X-Cart forums © 2001-2020