Forums / General Questions / Checkbox instead of buy now button on all products page

Checkbox instead of buy now button on all products page

Started by linuxguy2 on 27 Nov 2013, 5:49 PM · Views: 5,288

Results 21 to 40 of 58
29 Nov 2013, 3:44 AM
#21
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Checkbox instead of buy now button on all products page

Awesome!!!

I'll check it out in the AM and do some testing.
Thanks!!

29 Nov 2013, 5:48 AM
#22
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

Ups seems there's an extra quotation mark on the end of this code.

p.products_quantity_order_min, " : "") . " <-------**

I need to try it on a unmodified installation first and work backwards because my site is pretty heavily modified in the product display areas.

29 Nov 2013, 6:09 AM
#23
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Checkbox instead of buy now button on all products page

linuxguy2:

Ups seems there's an extra quotation mark on the end of this code.

p.products_quantity_order_min, " : "") . " <-------**

I need to try it on a unmodified installation first and work backwards because my site is pretty heavily modified in the product display areas.

It may seem so, but the next line (literally next line number: starts with a tabbed over variable that is to be pulled from the database (no quote) because php has been inserted (could have avoided the php check, but was thinking of things like, don't need to return a variable that is not going to be used, and it adds an additional pull from the database, so I added the logic check as well. If you follow each of the statements and substitute as you move along, you'll see that the last " is necessary to get back into the content of the SQL statement.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

29 Nov 2013, 4:18 PM
#24
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

Got it. Will work on this later today.
Got'ta go buy some black Friday stuff :)

30 Nov 2013, 5:51 AM
#25
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

Plugged your mods into a barebones install and it looks like it's not picking up the quantity.
check box gets checked and it goes through all the notions but beings the () is empty I guess there's nothing to add to the card. Your new check box option is turned on "1" in the admin.
Everything else is pretty much set to the defaults..

[Attachment no longer available]

30 Nov 2013, 6:15 AM
#26
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Checkbox instead of buy now button on all products page

linuxguy2:

Plugged your mods into a barebones install and it looks like it's not picking up the quantity.
check box gets checked and it goes through all the notions but beings the () is empty I guess there's nothing to add to the card. Your new check box option is turned on "1" in the admin.
Everything else is pretty much set to the defaults..

[Attachment no longer available]

Minimum quantity set for each item? And you did not try to put the header_php.php file. Intoa template directory? I would agree that at the moment either a value of zero is being returned or the sql is not correct to return a value. Any error logs?

Generally speaking it is setup right otherwise wouldn't be getting as much to choose from as currently, but definitely something about the return value for the minimum isn't correct yet.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

30 Nov 2013, 7:03 AM
#27
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Checkbox instead of buy now button on all products page

linuxguy2:

Plugged your mods into a barebones install and it looks like it's not picking up the quantity.
check box gets checked and it goes through all the notions but beings the () is empty I guess there's nothing to add to the card. Your new check box option is turned on "1" in the admin.
Everything else is pretty much set to the defaults..

[Attachment no longer available]

Can you post the contents of: shop/includes/modules/pages/products_all/header_php.php ?

Default for adding a product is to assign a min value of 1. If I remember correctly any file kept in the pages directory gets loaded, so don't try to "save" the old file there.. (It may be loaded after the one that has the changes and then the changes are overridden. I forget the intricacies of files in that directory, but thought anything in the directory got loaded which could cause an issue here if the old and new files are both in there.)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

30 Nov 2013, 4:21 PM
#28
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

I haven't had time to do a lot of troubleshooting

No I did not put it in an override but I made sure the original file isn't loading.
Your instructions didn't indicate that :-) Thought you might have a reason not to do that.

Also see NOTE below on how I handle that for testing.
NOTE:
When doing initial testing like this the way I handle files that need to be over ridden/replaced/delete is I re-name the base file xxxx_ORG.php
That way I know exactly which files have been replaced/overridden.
This works for every thing except the sideboxes as they get added to the list in the sidebox manager.....

Thanks

<?php /** * products_all header_php.php * * @package page * @copyright Copyright 2003-2007 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: header_php.php 6912 2007-09-02 02:23:45Z drbyte $ */ require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php')); $breadcrumb->add(NAVBAR_TITLE); // display order dropdown $disp_order_default = PRODUCT_ALL_LIST_SORT_DEFAULT; require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_LISTING_DISPLAY_ORDER)); $products_all_array = array(); /* Start Checkbox modification added p.products_quantity_order_min to query */ $products_all_query_raw = "SELECT p.products_type, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, " . (PRODUCT_ALL_CHECKBOX_ACTIVE ? "p.products_quantity_order_min, " : "") . " p.products_date_added, m.manufacturers_name, p.products_model, p.products_quantity, p.products_weight, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status, p.master_categories_id FROM " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_MANUFACTURERS . " m ON (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd WHERE p.products_status = 1 AND p.products_id = pd.products_id AND pd.language_id = :languageID " . $order_by; $products_all_query_raw = $db->bindVars($products_all_query_raw, ':languageID', $_SESSION['languages_id'], 'integer'); $products_all_split = new splitPageResults($products_all_query_raw, MAX_DISPLAY_PRODUCTS_ALL); //check to see if we are in normal mode ... not showcase, not maintenance, etc $show_submit = zen_run_normal(); // check whether to use multiple-add-to-cart, and whether top or bottom buttons are displayed if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 and $show_submit == true and $products_all_split->number_of_rows > 0) { // check how many rows $check_products_all = $db->Execute($products_all_split->sql_query); $how_many = 0; while (!$check_products_all->EOF) { if (zen_has_product_attributes($check_products_all->fields['products_id'])) { } else { // needs a better check v1.3.1 if ($check_products_all->fields['products_qty_box_status'] != 0) { if (zen_get_products_allow_add_to_cart($check_products_all->fields['products_id']) !='N') { if ($check_products_all->fields['product_is_call'] == 0) { if ((SHOW_PRODUCTS_SOLD_OUT_IMAGE == 1 and $check_products_all->fields['products_quantity'] > 0) or SHOW_PRODUCTS_SOLD_OUT_IMAGE == 0) { if ($check_products_all->fields['products_type'] != 3) { if (zen_has_product_attributes($check_products_all->fields['products_id']) < 1) { $how_many++; } } } } } } } $check_products_all->MoveNext(); } if ( (($how_many > 0 and $show_submit == true and $products_all_split->number_of_rows > 0) and (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART == 1 or PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART == 3)) ) { $show_top_submit_button = true; } else { $show_top_submit_button = false; } if ( (($how_many > 0 and $show_submit == true and $products_all_split->number_of_rows > 0) and (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART >= 2)) ) { $show_bottom_submit_button = true; } else { $show_bottom_submit_button = false; } } ?>
30 Nov 2013, 4:30 PM
#29
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

MY BAD!! You are absolutely correct. Any files in the "pages/xxxxx" folders get loaded.

I deleted my header_php_ORG.php and it works.
WOW!

This is a great lesson because I did not know that.
I have seen strange behavior with some of my other mods and this explains it.

I'll be doing more testing later today.

THANKS!!

30 Nov 2013, 5:39 PM
#30
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Checkbox instead of buy now button on all products page

linuxguy2:

I haven't had time to do a lot of troubleshooting

No I did not put it in an override but I made sure the original file isn't loading.
Your instructions didn't indicate that :-) Thought you might have a reason not to do that. I did have a reason not to state that... :) (Not that I didn't try to implement it though.. :) )

Also see NOTE below on how I handle that for testing.
NOTE:
When doing initial testing like this the way I handle files that need to be over ridden/replaced/delete is I re-name the base file xxxx**_ORG.php Young pad-won, you have yet more to learn today. :) Files that end with .php generally speaking are ALWAYS loaded, which also can cause problems. Renaming convention is some other extension ie. xxxx.php.old, xxxx.php.saveforlater, xxxx.php.beforecheckbox, etc...**
That way I know exactly which files have been replaced/overridden. You may know, but ZC in many cases thinks of it as just another file to load.
This works for every thing except the sideboxes as they get added to the list in the sidebox manager..... May appear to work, but probably have just been fortunate to date.. :)

linuxguy2:

MY BAD!! You are absolutely correct. Any files in the "pages/xxxxx" folders get loaded.

I deleted my header_php_ORG.php and it works.
WOW!

This is a great lesson because I did not know that.
I have seen strange behavior with some of my other mods and this explains it.

I'll be doing more testing later today.

THANKS!!
You're welcome. I'm still partially working on the same change for other "group" areas; however, am also trying to update my site's template, as the one we are using is long past due for a change (It ain't the month of July anymore...) I've also toyed with the definition that I said to add in so that can get some different representations of the text with the checkbox. I was thinking that the text should be specific, and possibly give some info to the user (without having to receive too much training). So had changed the definition to: ```
'Add%s: '


           $link = TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX . "(" . $products_all->fields['products_quantity_order_min'] . ") " . "<input type=\"checkbox\" name=\"products_id[" . $products_all->fields['products_id'] . "]\" value=\"". $products_all->fields['products_quantity_order_min'] . "\" size=\"4\" />";

to:

  $link = sprintf(TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX, " (" . $products_all->fields['products_quantity_order_min'] . ") Min Qty") . "<input type=\"checkbox\" name=\"products_id[" . $products_all->fields['products_id'] . "]\" value=\"". $products_all->fields['products_quantity_order_min'] . "\" size=\"4\" />";

This was more to show how it could be used than to properly format.  Afterall Min Qty is hard coded instead of using a language type relationship; however, again the concept is there that would allow a little more modification/maybe make it easier as compared to my submission.  To accomodate languages, could replace:

") Min Qty"
with
") " . DEFINED_MIN_QTY


Anyways, glad you're on a track that works and that you've learned a little more about ZC.  Hopefully it will help resolve some of your other issues if you go through your cart and "remove" the old files/rename them properly so that they are not loaded by the core code.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

3 Dec 2013, 8:43 PM
#31
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

mc12345678
Thank You for the code!!!

First off I corrected all my ill conceived file renaming conventions. :)
So far I have not encountered any functional issues.
I'll be loading up the store with some 1K items later this week so that will be the real test.
I do have a couple nits......

1:
As I suspected now my people want the checkboxes on the main products page. I told them to get in line.... :-)
They also asked for multiple checkboxes with incremental quantities. I'm not going to mess with the attributes as that opens up another can of worms.

2:
I modified your code (Removed text in red) so it wouldn't display the "Add (x) because that's already displayed right below the checkbox as a result of the global "min:" & "units:" code generated elsewhere. See Image.
I couldn't find a way to turn "min:" & "units:" off on a page by page basis.
Even if you set "TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX" to blank it still displays the (6) min quantity so you have a number hanging out to the left of the box.
If you do it to the All Products page then you have a (6) hanging out below the checkbox. I need to revisit that.....

[Attachment no longer available]

[start Checkbox modification /
if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0 && PRODUCT_ALL_CHECKBOX_ACTIVE) {
$link = TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX . "(" . $products_all->fields['products_quantity_order_min'] . ") " . "<input type="checkbox" name="products_id[" . $products_all->fields['products_id'] . "]" value="". $products_all->fields['products_quantity_order_min'] . "" size="4" />";
} /else//
end Checkbox modification: had to add else to next statement
/elseif (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0) {

3 Dec 2013, 9:33 PM
#32
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Checkbox instead of buy now button on all products page

linuxguy2:

mc12345678
Thank You for the code!!!

First off I corrected all my ill conceived file renaming conventions. :)
So far I have not encountered any functional issues.
I'll be loading up the store with some 1K items later this week so that will be the real test.
I do have a couple nits......

1:
As I suspected now my people want the checkboxes on the main products page. I told them to get in line.... :-)
They also asked for multiple checkboxes with incremental quantities. I'm not going to mess with the attributes as that opens up another can of worms.

2:
I modified your code (Removed text in red) so it wouldn't display the "Add (x) because that's already displayed right below the checkbox as a result of the global "min:" & "units:" code generated elsewhere. See Image.
I couldn't find a way to turn "min:" & "units:" off on a page by page basis.
Even if you set "TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX" to blank it still displays the (6) min quantity so you have a number hanging out to the left of the box.
If you do it to the All Products page then you have a (6) hanging out below the checkbox. I need to revisit that.....

[Attachment no longer available]

[start Checkbox modification /
if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0 && PRODUCT_ALL_CHECKBOX_ACTIVE) {
$link = TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX . "(" . $products_all->fields['products_quantity_order_min'] . ") " . "<input type="checkbox" name="products_id[" . $products_all->fields['products_id'] . "]" value="". $products_all->fields['products_quantity_order_min'] . "" size="4" />";
} /else//
end Checkbox modification: had to add else to next statement
/elseif (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0) {

So, looking back at my previous code, I realized that one of my "tests" made it in that code (PRODUCT_ALL_CHECKBOX_ACTIVE1)... Oops. Regarding your issue of the above extra paranthesis, I think the following change will address that issue, but I haven't tested it with a blank value in the english language define.... (Ie. I don't know if an error/warning will be generated if the string doesn't contain the %s option... (Trying to think of a couple of other ways to make it more "universal" and easy to adjust, but unfortunately it is not possible to define the variable with the "unknown" value assignment.)

Kind of figured that once one thing was seen as good, something else would be seen as such. Working out the other examples, I had created the following defines, though I'm curious what "listing" is going to be on the main page? Couldn't they just make the main page the all products listing?

Regarding the "incremental" check box, well may just have to loop through the number of check boxes desired (say 4 or 5 maybe?) and multiply the loop value by the minimum quantity for each? Or is it thought that start at minimum and have an option up to the next quantity that would be a factor of the minimum? (ie. minimum quantity of 4, so would have 4, 5, 6, and 7. Or minimum quantity of 8 then would have 8, 9, 10, 11, 12, 13, 14, 15. (so for I = minimum to minimum*2 - 1) with a check box placed next to the previous with some sort of number present. Not sure if this would work, but thinking that could use '$link .=' in the loop so that each button would be created? but then the minimum portion may not work out right, or another thought/possibility of using an array $link[] = as part of the loop. Now I'm just thinking and haven't tried that nor really looked at the code to see what will happen. It may be that some of the follow on code needs to come into the loop, or the loop encompass the existing code but with a proper escape to handle the other situations where a checkbox isn't used.

Regarding the text min and units, either css to hide the number for a given page or definition, or I thought there were custom css files that could be made for each product, category, etc.... so could hide those "characters" if you wanted to. The additional defines I had considered are:

  define('TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');
  define('TEXT_PRODUCT_FEATURED_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');
  define('TEXT_PRODUCT_NEW_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');

These would be referenced by similar code added to each of the applicable pages, headers, and SQL statements.
One thing about the SQL statements though, is that I would change the 26 in the below SQL statement to the next highest number for each (that is the sort order, could all be the same, but not a preferred method of listing.)

SQL to add setting:

INSERT INTO configuration (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `set_function`) VALUES ('Display Check Box for Checkout', 'PRODUCT_ALL_CHECKBOX_ACTIVE', 'false', 'Setting this value to 1 will force a checkbox to be displayed so that when checked, the minimum quantity for the product will be added to the store.', '23', '26', NULL, NOW(), 'zen_cfg_select_option(array(\'0\', \'1\'),');

in includes/languages/YOUR_TEMPLATE/english.php at around line 569 (Search for multiple product add to cart) and then add:

  define('TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');

in shop/includes/modules/pages/products_all/header_php.php

search for: $products_all_query_raw =

(Which should be around line 23)
replace that line with:

/* Start Checkbox modification added p.products_quantity_order_min to query */
$products_all_query_raw = "SELECT p.products_type, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, " . (PRODUCT_ALL_CHECKBOX_ACTIVE ? "p.products_quantity_order_min, " : "") . "

Do not replace any lines past that.

Copy SHOP\includes\templates\template_default\templates\tpl_modules_products_all_listing.php to:

SHOP\includes\templates\YOUR_TEMPLATE\templates\tpl_modules_products_all_listing.php
Then at line 90 looking for: ```
if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0) {


essentially replace that line with this:

/start Checkbox modification /
if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0 && PRODUCT_ALL_CHECKBOX_ACTIVE) {
$link = sprintf(TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX, " (" . $products_all->fields['products_quantity_order_min'] . ") Min Qty") . "<input type="checkbox" name="products_id[" . $products_all->fields['products_id'] . "]" value="". $products_all->fields['products_quantity_order_min'] . "" size="4" />";
} /else//
end Checkbox modification: had to add else to next statement
/elseif (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0) {

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

3 Dec 2013, 10:13 PM
#33
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Checkbox instead of buy now button on all products page

mc12345678:

So, looking back at my previous code, I realized that one of my "tests" made it in that code (PRODUCT_ALL_CHECKBOX_ACTIVE1)... Oops. Regarding your issue of the above extra paranthesis, I think the following change will address that issue, but I haven't tested it with a blank value in the english language define.... (Ie. I don't know if an error/warning will be generated if the string doesn't contain the %s option... (Trying to think of a couple of other ways to make it more "universal" and easy to adjust, but unfortunately it is not possible to define the variable with the "unknown" value assignment.)

Kind of figured that once one thing was seen as good, something else would be seen as such. Working out the other examples, I had created the following defines, though I'm curious what "listing" is going to be on the main page? Couldn't they just make the main page the all products listing?

Regarding the "incremental" check box, well may just have to loop through the number of check boxes desired (say 4 or 5 maybe?) and multiply the loop value by the minimum quantity for each? Or is it thought that start at minimum and have an option up to the next quantity that would be a factor of the minimum? (ie. minimum quantity of 4, so would have 4, 5, 6, and 7. Or minimum quantity of 8 then would have 8, 9, 10, 11, 12, 13, 14, 15. (so for I = minimum to minimum*2 - 1) with a check box placed next to the previous with some sort of number present. Not sure if this would work, but thinking that could use '$link .=' in the loop so that each button would be created? but then the minimum portion may not work out right, or another thought/possibility of using an array $link[] = as part of the loop. Now I'm just thinking and haven't tried that nor really looked at the code to see what will happen. It may be that some of the follow on code needs to come into the loop, or the loop encompass the existing code but with a proper escape to handle the other situations where a checkbox isn't used.

Regarding the text min and units, either css to hide the number for a given page or definition, or I thought there were custom css files that could be made for each product, category, etc.... so could hide those "characters" if you wanted to. The additional defines I had considered are:

define('TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');
define('TEXT_PRODUCT_FEATURED_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');
define('TEXT_PRODUCT_NEW_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');

> 
> These would be referenced by similar code added to each of the applicable pages, headers, and SQL statements.
> One thing about the SQL statements though, is that I would change the 26 in the below SQL statement to the next highest number for each (that is the sort order, could all be the same, but not a preferred method of listing.)
> 
> SQL to add setting:
> ```
INSERT INTO configuration (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `set_function`) VALUES ('Display Check Box for Checkout', 'PRODUCT_ALL_CHECKBOX_ACTIVE', 'false', 'Setting this value to 1 will force a checkbox to be displayed so that when checked, the minimum quantity for the product will be added to the store.', '23', '26', NULL, NOW(), 'zen_cfg_select_option(array(\'0\', \'1\'),');

in includes/languages/YOUR_TEMPLATE/english.php at around line 569 (Search for multiple product add to cart) and then add:

define('TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');

> 
> 
> in shop/includes/modules/pages/products_all/header_php.php
> 
> search for: $products_all_query_raw = 
> 
> (Which should be around line 23)
> replace that line with:
> ```
/* Start Checkbox modification added p.products_quantity_order_min to query */
$products_all_query_raw = "SELECT p.products_type, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, " . (PRODUCT_ALL_CHECKBOX_ACTIVE ? "p.products_quantity_order_min, " : "") . "

Do not replace any lines past that.

Copy SHOP\includes\templates\template_default\templates\tpl_modules_products_all_listing.php to:

SHOP\includes\templates\YOUR_TEMPLATE\templates\tpl_modules_products_all_listing.php
Then at line 90 looking for: ```
if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0) {

> 
> essentially replace that line with this:
> ```
/*start Checkbox modification */
           if (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0 && PRODUCT_ALL_CHECKBOX_ACTIVE) {
               $link = sprintf(TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX, " (" . $products_all->fields['products_quantity_order_min'] . ") Min Qty") . "<input type=\"checkbox\" name=\"products_id[" . $products_all->fields['products_id'] . "]\" value=\"". $products_all->fields['products_quantity_order_min'] . "\" size=\"4\" />";
           }  /*else*//* end Checkbox modification: had to add else to next statement*/elseif (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 && $products_all->fields['products_qty_box_status'] != 0) {

Fyi, if the above sprintf does cause an error, then a check could be performed in front of it,so that nothing is added: ```
(substr(DEFINEDVARIARIABLE, '%s') !== false ? Sprintf info : (DEFINEDVARIARIABLE !== '' ? DEFINEDVARIARIABLE : '') )

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

5 Dec 2013, 5:54 AM
#34
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

Right now we're displaying the "New Products" on the main page.

On the "Products" page a check box just like the one you coded up for the "All Products" page would suffice for now.
For those who want to use Attributes or Sub categories it might be much more complicated.

You can almost get there with a combination of the existing features it's just that you don't have the check box.

I'm going to start out with the check boxes on the "All Products" page and see if that's stable then worry about the "Products" page stuff later.

Thanks,

12 Dec 2013, 1:03 AM
#35
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

Is this possible?

zc 1.5.1

On the main products page display a box with the min qty in it with the ability to adjust those quantities AND have a check box WITH the "add selected products to cart" button.
Having that feature across all products pages would be the holy grail.

Example settings below.
1:
Display Product Price/Add to Cart (some positive value)
2:
Display Product Add to Cart Button (0=off; 1=on; 2=on with Qty Box per Product) (2)
Need a third option above that is a check box instead of the ".... more info" or "buy now button" or "add to cart button"
3:
Display Multiple Products Qty Box Status and Set Button Location (3)
Currently ZC says you should set the above to zero if option #1 or #2 is selected in bullet #2 above..

Bottom line is I'm looking for a check box with an editable "qty box" defaulted to "min qty" and the "add selected products to cart" button on the main products page.

Thanks Lucien

12 Dec 2013, 2:54 PM
#36
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

Clarification:
Bottom line is I'm looking for a check box with an editable "qty box" defaulted to "min qty" and the "add selected products to cart" button on the main products pages when you choose a "Category"

12 Dec 2013, 11:48 PM
#37
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Checkbox instead of buy now button on all products page

linuxguy2:

Clarification:
Bottom line is I'm looking for a check box with an editable "qty box" defaulted to "min qty" and the "add selected products to cart" button on the main products pages when you choose a "Category"

Kind of figured that out from the previous message, but fully appreciate the succinct version.

I have an idea, but would want to test first. Concept uses the following:
An additional define to be configurable in the admin panel. Seeing that want just on the one page, would name it applicably.

That option would override the setting for the checkbox (so regardless of the checkbox setting this option would be in place). Or maybe add an option to fill-in/select the sheets desired to be active.

Similar header info in the applicable header file.

If the desired page is being shown, and the checkbox and min field are to be shown, then display both a checkbox and textbox named similar, but some difference to later process them separately. Set the value of the new checkbox to 1, and the textbox to the minimum value.

On processing the add to cart, if the sheet was shown (may require a post variable in previous screen load) and the option to do a checkbox/textbox combo is true, then as part of cycling through all the products if the checkbox times the textbox <> 0 then add the quantity of the product. Otherwise if process the products as normal.

Regarding only having a text box and not having the clickable link to see more detail, well, suggestion would be to not have products that have attributes, or ensure that they are products that do not show on the applicable page. What could be done is to add each of the products without their corresponding attribute so that it shows up in the list/category of choice.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

16 Dec 2013, 2:17 AM
#38
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Checkbox instead of buy now button on all products page

mc12345678:

Kind of figured that out from the previous message, but fully appreciate the succinct version.

I have an idea, but would want to test first. Concept uses the following:
An additional define to be configurable in the admin panel. Seeing that want just on the one page, would name it applicably.

That option would override the setting for the checkbox (so regardless of the checkbox setting this option would be in place). Or maybe add an option to fill-in/select the sheets desired to be active.

Similar header info in the applicable header file.

If the desired page is being shown, and the checkbox and min field are to be shown, then display both a checkbox and textbox named similar, but some difference to later process them separately. Set the value of the new checkbox to 1, and the textbox to the minimum value.

On processing the add to cart, if the sheet was shown (may require a post variable in previous screen load) and the option to do a checkbox/textbox combo is true, then as part of cycling through all the products if the checkbox times the textbox <> 0 then add the quantity of the product. Otherwise if process the products as normal.

Regarding only having a text box and not having the clickable link to see more detail, well, suggestion would be to not have products that have attributes, or ensure that they are products that do not show on the applicable page. What could be done is to add each of the products without their corresponding attribute so that it shows up in the list/category of choice.

Okay, so here is the above as it was implemented. It also revealed a change to the original solution, which is shown below in the tpl_modules_products_all_listing.php file. Line numbers refer to the original line number before any additions are made, and all code additions are shown in sequence from top to bottom. Therefore, to correctly insert/replace the correct line numbers, suggest working from the back of the file (last line number in the file) to the front.

Implementation of a checkbox only or combination for specials, new, and featured product listings (category selected) is not incorporated for product listings by the below. Only for the all products options... Additional coding would be necessary to incorporate those additional options elsewhere. Line numbers are provided from what appears to be ZC 1.5.1 base install. So, generally speaking a shift may be necessary if in my implementation I kept old commented lines. I have gone ahead and included one active line before and one active line after the changes I made, so please pay attention as you follow the written directions about going to a line and replacing... But overall the insertion/replacement should make sense when looked at...

So, here is how the below new checkboxes with or without textbox works. If the checkbox and textbox are on, then when first presented, the textbox will contain the minimum number of items necessary for that product to meet the minimum number to be added to the cart. After the minimum number of the product has been added to the cart, then when the product is shown again for choosing, it is the minimum interval, step, or unit that will be presented next provided some of the previous math has worked out, otherwise it may be that a value of 1 is added to the cart.

The following files were modified to provide the checkbox/textbox combination that was requested so far to date:

includes/modules/YOUR_TEMPLATE/product_listing.php
includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php
includes/classes/YOUR_TEMPLATE/shopping_cart.php
includes/languages/YOUR_TEMPLATE/english.php
SQLDatabase had values added (and some of the previous options have been modified, so I recommend removing the previous table entries in favor of the below.)

Database mods SQL Statement:

INSERT INTO  configuration (`configuration_title`, `configuration_key`,  `configuration_value`, `configuration_description`,  `configuration_group_id`, `sort_order`, `last_modified`, `date_added`,  `set_function`) VALUES ('Display Check Box and Text Box for Checkout',  'PRODUCT_LISTING_CHECKBOX_TEXTBOX_ACTIVE', '0', 'Setting this value to 1  will force a checkbox to be displayed so that when checked, the minimum  quantity (or greater value as entered in the text box) for the product  will be added to the store.<br/><br/>This value overrides  the check box for checkout setting.', '8', '26', NOW(), NOW(),  'zen_cfg_select_option(array(\'0\', \'1\'),');
INSERT INTO  configuration (`configuration_title`, `configuration_key`,  `configuration_value`, `configuration_description`,  `configuration_group_id`, `sort_order`, `last_modified`, `date_added`,  `set_function`) VALUES ('Display Check Box for Checkout',  'PRODUCT_LISTING_CHECKBOX_ACTIVE', '0', 'Setting this value to 1 will  force a  checkbox to be displayed so that when checked, the minimum quantity for  the product will be added to the store.<br/><br/>This value  is overridden by the check box and text box option for checkout  setting.', '8', '27', NOW(), NOW(),  'zen_cfg_select_option(array(\'0\', \'1\'),');
INSERT INTO  configuration (`configuration_title`, `configuration_key`,  `configuration_value`, `configuration_description`,  `configuration_group_id`, `sort_order`, `last_modified`, `date_added`,  `set_function`) VALUES ('Display Check Box and Text Box for Checkout',  'PRODUCT_ALL_CHECKBOX_TEXTBOX_ACTIVE', '0', 'Setting this value  to 1 will force a checkbox to be displayed so that when checked, the  minimum quantity (or greater value as entered in the text box) for the  product will be added to the store.<br/><br/>This value  overrides the check box for checkout setting.', '23', '30', NOW(),  NOW(),  'zen_cfg_select_option(array(\'0\', \'1\'),');
INSERT INTO  configuration (`configuration_title`, `configuration_key`,  `configuration_value`, `configuration_description`,  `configuration_group_id`, `sort_order`, `last_modified`, `date_added`,  `set_function`) VALUES ('Display Check Box for Checkout',  'PRODUCT_ALL_CHECKBOX_ACTIVE', '0', 'Setting this value to 1 will force a  checkbox to be displayed so that when checked, the minimum quantity for  the product will be added to the store.<br/><br/>This value  is overridden by the check box and text box option for checkout  setting.', '23', '26', NOW(), NOW(), 'zen_cfg_select_option(array(\'0\',  \'1\'),');

Changes/modifications:

includes/modules/YOUR_TEMPLATE/product_listing.php
at line 130 insert the following:

               $lc_button = '<a href="' . zen_href_link($_GET['main_page'],  zen_get_all_get_params(array('action')) .  'action=buy_now&products_id=' . $listing->fields['products_id']) .  '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT,  'class="listingBuyNowButton"') . '</a>';
            } elseif (PRODUCT_LISTING_CHECKBOX_TEXTBOX_ACTIVE) {
             $lc_button =  sprintf(TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX, " (" .  (zen_get_buy_now_qty($listing->fields['products_id'])) . ") Min Qty")  . "<input type=\"checkbox\" name=\"products_id2[" .  $listing->fields['products_id'] . "]\" value=\"1\" size=\"4\"  /><input type=\"textbox\" name=\"products_id[" .  $listing->fields['products_id'] . "]\" value=\"" .  (zen_get_buy_now_qty($listing->fields['products_id'])) . "\"  size=\"4\" />";
            } elseif (PRODUCT_LISTING_CHECKBOX_ACTIVE) {
             $lc_button =  sprintf(TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX, " (" .  (zen_get_buy_now_qty($listing->fields['products_id'])) . ") Min Qty")  . "<input type=\"checkbox\" name=\"products_id[" .  $listing->fields['products_id'] . "]\" value=\"" .  (zen_get_buy_now_qty($listing->fields['products_id'])) . "\"  size=\"4\"  />";
          } else {

at line 217 insert the following:

     echo zen_draw_form('multiple_products_cart_quantity',  zen_href_link(FILENAME_DEFAULT, zen_get_all_get_params(array('action')) .  'action=multiple_products_add_product', $request_type), 'post',  'enctype="multipart/form-data"');
    if ((PRODUCT_LISTING_CHECKBOX_TEXTBOX_ACTIVE == true)) {
        echo zen_draw_hidden_field('check_text_active', true); 
    }
    }

includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php
at line 25 insert the following:

    $row_counter = 0;
    if ((PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0) && (PRODUCT_ALL_CHECKBOX_TEXTBOX_ACTIVE == true)) {
        echo zen_draw_hidden_field('check_text_active', true); 
    }

    while (!$products_all->EOF) {

at line 90 replace the line with the following:

        } else {

//           $link= '<a href="' . zen_href_link(FILENAME_PRODUCTS_ALL,  zen_get_all_get_params(array('action')) .  'action=buy_now&products_id=' .  $products_all->fields['products_id']) . '">' .  zen_image_button(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) .  '</a>';
           /*start Checkbox modification */
            if ((PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0) &&  ($products_all->fields['products_qty_box_status'] != 0) &&  (PRODUCT_ALL_CHECKBOX_TEXTBOX_ACTIVE == true)) {
               $link  = sprintf(TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX, " (" .  (zen_get_buy_now_qty($products_all->fields['products_id'])) . ") Min  Qty") . "<input type=\"checkbox\" name=\"products_id2[" .  $products_all->fields['products_id'] . "]\" value=\"1\" size=\"4\"  /><input type=\"textbox\" name=\"products_id[" .  $products_all->fields['products_id'] . "]\" value=\"" .  (zen_get_buy_now_qty($products_all->fields['products_id'])) . "\"  size=\"4\" />";
           } elseif  ((PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0) &&  ($products_all->fields['products_qty_box_status'] != 0) &&  (PRODUCT_ALL_CHECKBOX_ACTIVE == true)) {
               $link =  sprintf(TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX, " (" .  (zen_get_buy_now_qty($products_all->fields['products_id'])) . ") Min  Qty") . "<input type=\"checkbox\" name=\"products_id[" .  $products_all->fields['products_id'] . "]\" value=\"".  (zen_get_buy_now_qty($products_all->fields['products_id'])) . "\"  size=\"4\" />";
           }  /* end Checkbox modification*/  elseif (PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART > 0 &&  $products_all->fields['products_qty_box_status'] != 0) {
//            $how_many++;
             $link = TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART . "<input  type=\"text\" name=\"products_id[" .  $products_all->fields['products_id'] . "]\" value=\"0\" size=\"4\"  />";

in includes/classes/YOUR_TEMPLATE/shopping_cart.php
at line 1836 insert the following:

    if (is_array($_POST['products_id']) && sizeof($_POST['products_id']) > 0) {
        if ($_POST['check_text_active'] == true) {
            $multiAddCheck = true;
        } else {
            $multiAddCheck = false;
        }

        while ( list( $key, $val ) = each($_POST['products_id']) ) {
             if ((PRODUCT_ALL_CHECKBOX_TEXTBOX_ACTIVE == true ||  PRODUCT_LISTING_CHECKBOX_TEXTBOX_ACTIVE == true) &&  $multiAddCheck == true){
                
                while ( list( $key2, $val2 ) = each($_POST['products_id2']) ) {
                 if ($key == $key2) {
                     if ($val > 0) 
                {
                    $adjust_max = false;
                    $prodId = preg_replace('/[^0-9a-f:.]/', '', $key);
                    $qty = $val;
                    $add_max = zen_get_products_quantity_order_max($prodId);
                    $cart_qty = $this->in_cart_mixed($prodId);
            //        $new_qty = $qty;
            //echo 'I SEE actionMultipleAddProduct: ' . $prodId . '<br>';
                    $new_qty = $this->adjust_quantity($qty, $prodId, 'shopping_cart');
                            
                    if (($add_max == 1 and $cart_qty == 1)) {
                    // do not add
                    $adjust_max= 'true';
                    } else {
                    // adjust quantity if needed
                    if (($new_qty + $cart_qty > $add_max) and $add_max != 0) {
                    $adjust_max= 'true';
                    $new_qty = $add_max - $cart_qty;
                    }
                    $this->add_cart($prodId, $this->get_quantity($prodId)+($new_qty));
                    $addCount++;
                    }
                    if ($adjust_max == 'true') {
             //            $messageStack->add_session('shopping_cart',  ERROR_MAXIMUM_QTY . ' C: - ' . zen_get_products_name($prodId),  'caution');
             //$messageStack->add_session('shopping_cart',  'actionMultipleAddProduct<br>' . ERROR_MAXIMUM_QTY .  zen_get_products_name($prodId), 'caution');
                     $messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY .  zen_get_products_name($prodId), 'caution');
                    }
                }
                break; /*Add product, otherwise don't add */ 
                
                }
             }
            reset($_POST['products_id2']);

         } elseif ($val > 0) {

          $adjust_max = false;

in includes/languages/YOUR_TEMPLATE/english.php
around line 555 added to address all expected future options:

  define('TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');
  define('TEXT_PRODUCT_ALL_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');
  define('TEXT_PRODUCT_NEW_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');
  define('TEXT_PRODUCT_FEATURED_LISTING_MULTIPLE_ADD_TO_CART_CHECKBOX', 'Add%s: ');

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

16 Dec 2013, 6:02 PM
#39
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

Thanks, First I'll take it for a spin on a new install.

18 Dec 2013, 4:26 PM
#40
linuxguy2 avatar

linuxguy2

Zen Follower

Join Date:
Sep 2013
Location:
Texas
Posts:
315
Plugin Contributions:
0

Re: Checkbox instead of buy now button on all products page

ZC 1.5.1

Beside being difficult to implement, a checkbox feature on the "Products" has some short comings.
A increment by minimum quantity "button" would work much better for mobile devices.
That way one could tap the "Button" or type in the quantities.

[Attachment no longer available]

If I'm not mistaken all the logic should already be in ZC so the question is how to implement it.
I guess that means one would add a third option to the admin section or it could be a separate option.

[Attachment no longer available]