Jump to content

Comparison mod for cart


Recommended Posts

I wanted to customize the first page of the order process to have a comparison table instead of the row by row list of available products they give you by default. I went to edit the template (/templates/orderforms/web20cart/products.tpl) but I realized the they don't set all of the product variables that I need to be able to give the comparison.

 

Here's the solution I came up with. It's just a block of PHP code that can sit in {php}{/php} smarty tags or an include file at the top of products.tpl. It's purpose is to replace the WHMCS generated variables with a more complete set, while preserving the original variable structure so as to not break the default templates. Once it's in place, you have a whole slew of more variables to call in your template to build your own comparison form.

 

To see what variables are available, put this line in your template:

<textarea rows="10" cols="100">{php}print_r($this->_tpl_vars['products']);{/php}</textarea>

// Get the product group being displayed
$gid = $this->_tpl_vars['gid'];

// Query all non-hidden products in current group
$query = "SELECT *
FROM `tblproducts`
WHERE `hidden`=''
AND `gid`=$gid
ORDER BY `order` ASC";

// Store queried products in $products array
$products = array();
$result = mysql_query($query);
while ($data = mysql_fetch_array($result,MYSQL_ASSOC)) {
 $products[] = $data;
}

// Get the pricing for each product
for ($i = 0; $i < count($products); $i++) {
 $query = "SELECT `msetupfee`, `qsetupfee`, `ssetupfee`, `asetupfee`, `bsetupfee`, `monthly`, `quarterly`, `semiannually`, `annually`, `biennially`
   FROM `tblpricing`
   WHERE `type`='product'
   AND `relid`='" . $products[$i]['id'] . "'";
   $result = mysql_query($query);
   while ($data = mysql_fetch_array($result,MYSQL_ASSOC)) {
     $products[$i]['pricing']['rawpricing'] = $data;
     foreach ($products[$i]['pricing']['rawpricing'] as $key => $data) {
       if ($data != -1.00) $products[$i]['pricing'][$key] = formatCurrency($data);
     }
     // Put some other variables in places where WHMCS expects them
     $products[$i]['pricing']['type'] = $products[$i]['paytype'];
     $products[$i]['pid'] = $products[$i]['id'];
     // Make sure quantities work correctly when turned off
     if ($products[$i]['stockcontrol'] == '') $products[$i]['qty'] = '';
   }
}

// Unset the WHMCS generated smarty tokens
$this->clear_assign('products');

// Set new smarty tokens
$this->assign('products', $products);

 

I haven't built my new template yet, but I'll share that too when I'm done. You can apply this to the default template and customize it from there. The only thing that should appear differently on the default template is I removed the billing term from the price list. (Ex. $10.00 USD Monthly = $10.00 USD). I did this because the term can still be added to the template directly, and may not be desired in all scenarios.

 

Maybe this will help somebody else. If anybody finds any bugs or has any suggestions let me know and I'll post the fix.

Link to comment
Share on other sites

I've already made some changes to the script above, there were a few things I needed to tweak/fix in it. Since it's still a work in progress I'm not going to keep pasting each version. If anyone is interested send me a PM and I'll share what I have at the time. If there's any interest I'll see about bundling it up into a package.

Link to comment
Share on other sites

  • 2 weeks later...

No huge rush, let's say next 2 hours? :D

No seriously, next week or so will be fine.

 

If you can make it so no core files need to be modified I think most of us would appreciate that.

 

Best to have as a single php file to add into our template folder that calls our header/footer?

 

Many thanks for your time on this.

 

- Vincent

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated