Shopping Cart Software

Shopping Cart Software ClickCartPro XCS Version
corner image corner image

Move Add to Basket and Add to Wishlist Buttons

Move Add to Basket and Add to Wishlist Buttons

Postby LDW » 09 Aug 2010 19:05

I am trying to modify {private}/apps/gbu0/GBU/includes/form_header.php to display both the Add to Basket and Add to Wish List buttons (if applicable to current store configuration), and having real fun trying to understand how things are working (or not, as the case maybe).

After several hours work I have managed to come up with the following, which works perfectly provided I want a working Add to Wish List button or a working Add to Basket button ...but not both :?

Currently the following code block gives me a working Add to Basket button...

Code: Select all
<?php

$app          = $this->globals('khxc_display.app');
$form         = $this->xhtml_encode($this->globals('khxc_form.form'));
$formid       = $this->xhtml_encode($this->globals('khxc_form.formid'));
$url          = $this->xhtml_encode($this->globals('khxc_form.url'));
$upload       = $this->globals('khxc_form.upload');
$required     = $this->globals('khxc_form.required');
$desc_has_tags = $this->has_tags($this->globals('khxc_form.description'));
$buttname     = $this->globals('khxc_form.submit_modify');
$disablewl    = $this->globals('khxc_settings.' . $app . '.disablewishlist');



if (empty($buttname)) {$buttname = 'Submit';}
else {$buttname = $this->xhtml_encode($buttname);}

$isaddtocart = 0;

if (preg_match('/\-\-prodaddtocart/',$formid)) {$isaddtocart = 1;}

print '<p>';



if (empty($buttname)) {$buttname = 'Submit';}
else {$buttname = $this->xhtml_encode($buttname);}

$show_wl = 0;

if (preg_match('/\-\-prodaddtocart/',$formid)) {$show_wl = 1;}
if (!(empty($disablewl)))                       {$show_wl = 0;}

$method = 'post';

if (preg_match('/\-\-prodsearch/',$formid)) {$method = 'get';}
if (preg_match('/\-\-minisearch/',$formid)) {$method = 'get';}

if ($desc_has_tags) {

     $description  = $this->globals('khxc_form.description');

} else {

     $description  = $this->xhtml_encode($this->globals('khxc_form.description'));

} // End of if statement.



if (empty($isaddtocart)) {

     print '<br /><p style="padding: 0 0 0 10px;" /></form><input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
     print $formid . '--SUBMIT" value="' . $buttname;
     print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
     print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

     print ' <input class="khxc_formbutton" type="submit" name="ns" id="';
     print $formid . '--CANCEL" value="Cancel" /></p><br />';

} else {

     print '<input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
     print $formid . '--SUBMIT" value="' . $buttname;
     print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
     print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

     if (empty($disablewl)) {

          print ' <input class="khxc_formbutton" type="submit" name="WISHLIST" id="';
          print $formid . '--WISHLIST" value="Would Like To Purchase" />';

     } // End of if statement.

} // End of if statement.



if ($upload) {

     print '<form action="' . $url . '" method="' . $method . '" id="' . $formid . '" enctype="multipart/form-data" >' . $eol . $eol;

} else {

     print '<form action="' . $url . '" method="' . $method . '" id="' . $formid . '">' . $eol . $eol;

} // End of if statement.



?>


...whilst

Code: Select all
<?php

$app          = $this->globals('khxc_display.app');
$form         = $this->xhtml_encode($this->globals('khxc_form.form'));
$formid       = $this->xhtml_encode($this->globals('khxc_form.formid'));
$url          = $this->xhtml_encode($this->globals('khxc_form.url'));
$upload       = $this->globals('khxc_form.upload');
$required     = $this->globals('khxc_form.required');
$desc_has_tags = $this->has_tags($this->globals('khxc_form.description'));
$buttname     = $this->globals('khxc_form.submit_modify');
$disablewl    = $this->globals('khxc_settings.' . $app . '.disablewishlist');



if (empty($buttname)) {$buttname = 'Submit';}
else {$buttname = $this->xhtml_encode($buttname);}

$isaddtocart = 0;

if (preg_match('/\-\-prodaddtocart/',$formid)) {$isaddtocart = 1;}

print '<p>';



if (empty($buttname)) {$buttname = 'Submit';}
else {$buttname = $this->xhtml_encode($buttname);}

$show_wl = 0;

if (preg_match('/\-\-prodaddtocart/',$formid)) {$show_wl = 1;}
if (!(empty($disablewl)))                       {$show_wl = 0;}

$method = 'post';

if (preg_match('/\-\-prodsearch/',$formid)) {$method = 'get';}
if (preg_match('/\-\-minisearch/',$formid)) {$method = 'get';}

if ($desc_has_tags) {

     $description  = $this->globals('khxc_form.description');

} else {

     $description  = $this->xhtml_encode($this->globals('khxc_form.description'));

} // End of if statement.



if ($upload) {

     print '<form action="' . $url . '" method="' . $method . '" id="' . $formid . '" enctype="multipart/form-data" >' . $eol . $eol;

} else {

     print '<form action="' . $url . '" method="' . $method . '" id="' . $formid . '">' . $eol . $eol;

} // End of if statement.



if (empty($isaddtocart)) {

     print '<br /><p style="padding: 0 0 0 10px;" /></form><input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
     print $formid . '--SUBMIT" value="' . $buttname;
     print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
     print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

     print ' <input class="khxc_formbutton" type="submit" name="ns" id="';
     print $formid . '--CANCEL" value="Cancel" /></p><br />';

} else {

     print '<input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
     print $formid . '--SUBMIT" value="' . $buttname;
     print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
     print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

     if (empty($disablewl)) {

          print ' <input class="khxc_formbutton" type="submit" name="WISHLIST" id="';
          print $formid . '--WISHLIST" value="Would Like To Purchase" />';

     } // End of if statement.

} // End of if statement.
?>

gives me a working Add to Wishlist button


Ideally I would like to strip the code for the buttons to an absolute minimum in terms of dependencies and variables in order to allow it to be usable not just within form_header.php, but also within Catalog Product Display files, so's to allow the buttons to be displayed anywhere within the product listing.

There is also the quantity box to think about, but that is usually quite straightforward to implement and I will detail the process of implementing it later on in this post if I can get the buttons repositioned and working.

Can anyone help with this, please?
LDW
 
Posts: 17
Joined: 09 Aug 2010 18:48

Re: Move Add to Basket and Add to Wishlist Buttons

Postby GreenbarnWeb » 10 Aug 2010 09:11

Hi
Try this should work to put both buttons at the top of the form:
Code: Select all
<?php

$app          = $this->globals('khxc_display.app');
$form         = $this->xhtml_encode($this->globals('khxc_form.form'));
$formid       = $this->xhtml_encode($this->globals('khxc_form.formid'));
$url          = $this->xhtml_encode($this->globals('khxc_form.url'));
$upload       = $this->globals('khxc_form.upload');
$required     = $this->globals('khxc_form.required');
$desc_has_tags = $this->has_tags($this->globals('khxc_form.description'));
$buttname     = $this->globals('khxc_form.submit_modify');
$disablewl    = $this->globals('khxc_settings.' . $app . '.disablewishlist');



if (empty($buttname)) {$buttname = 'Submit';}
else {$buttname = $this->xhtml_encode($buttname);}

$isaddtocart = 0;

if (preg_match('/\-\-prodaddtocart/',$formid)) {$isaddtocart = 1;}

print '<p>';



if (empty($buttname)) {$buttname = 'Submit';}
else {$buttname = $this->xhtml_encode($buttname);}

$show_wl = 0;

if (preg_match('/\-\-prodaddtocart/',$formid)) {$show_wl = 1;}
if (!(empty($disablewl)))                       {$show_wl = 0;}

$method = 'post';

if (preg_match('/\-\-prodsearch/',$formid)) {$method = 'get';}
if (preg_match('/\-\-minisearch/',$formid)) {$method = 'get';}

if ($desc_has_tags) {

     $description  = $this->globals('khxc_form.description');

} else {

     $description  = $this->xhtml_encode($this->globals('khxc_form.description'));

} // End of if statement.



if ($upload) {

     print '<form action="' . $url . '" method="' . $method . '" id="' . $formid . '" enctype="multipart/form-data" >' . $eol . $eol;

} else {

     print '<form action="' . $url . '" method="' . $method . '" id="' . $formid . '">' . $eol . $eol;

} // End of if statement.



if (empty($isaddtocart)) {

     print '<br /><p style="padding: 0 0 0 10px;" /></form><input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
     print $formid . '--SUBMIT" value="' . $buttname;
     print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
     print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

     print ' <input class="khxc_formbutton" type="submit" name="ns" id="';
     print $formid . '--CANCEL" value="Cancel" /></p><br />';

} else {

     print '<input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
     print $formid . '--SUBMIT" value="' . $buttname;
     print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
     print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

     if ($show_wl) {

          print ' <input class="khxc_formbutton" type="submit" name="WISHLIST" id="';
          print $formid . '--WISHLIST" value="Would Like To Purchase" />';

     } // End of if statement.

} // End of if statement.
?>

There is also the quantity box to think about, but that is usually quite straightforward to implement and I will detail the process of implementing it later on in this post if I can get the buttons repositioned and working.

That would need some work to add a new type of form field type.
Howard Galpin
http://www.greenbarnweb.com
http://www.clickcartpro.co.uk - UK Customised version
http://www.clickcartpro.eu.com - European Customised version
GreenbarnWeb
Site Admin
 
Posts: 1153
Joined: 29 Jul 2009 10:58

Re: Move Add to Basket and Add to Wishlist Buttons

Postby LDW » 10 Aug 2010 09:47

That works a treat - completely fantastic! - thank-you!!

...and, yes, I made a mistake with the quantity box - I was thinking about using the product global to increment quantities so, no, I am not actually sure about modifying that for a form display, but... let me play with the code a little later on today and if I still cannot get a handle on this form layout I will request some more pointers then.

Meantime, again, thank-you!
LDW
 
Posts: 17
Joined: 09 Aug 2010 18:48

Re: Move Add to Basket and Add to Wishlist Buttons

Postby LDW » 10 Aug 2010 23:06

I have not been able to get this code to display right at the top, or above, the product listings, which is a real dissapointment. - The only way to get the code to display above the product listings, but below the breadcrumb paths, and still be within the prodshow namespace seems to be by placing it into the prodshow function code block within the GBU_Prod.php file, which I could not get to work.

Failing that, placing it inside a file under Manage Catalog Product Displays: Detail View prevented the required globals from working - so the buttons displayed as Submit and Cancel and, of course, would not function as Add to Cart or Add to Wishlist. - So could this be modified for implementation within GBU_Prod.php to allow the buttons (again, the quantity box is not essential here) to be displayed, as stated above, ie: below the breadcrumb paths but above the product listings? - I don't mind paying for a support ticket, if necessary, should this require some major modification because it is something that I feel would definitely make a difference within my store (although I would want the quantity box adding, too, if I was paying for a support ticket! :mrgreen: )

Other than that, I hit some problems with the code affecting the guest checkout form [or rather, I had to spend half an hour with a rather exasperated customer who could not figure out why they were going round and round in circles with my (then) multiple-line mult-button layout :? ], so I modified the button display statement from the above code by modifying the if statement for the buttons ...only to find that the code as a whole replacement for form_header.php killed the guest checkout process. So... a good day later I now have the code displayed below, which works and validates and which does not kill the guest checkout:

Code: Select all
<?php

$app           = $this->globals('khxc_display.app');
$form          = $this->xhtml_encode($this->globals('khxc_form.form'));
$formid        = $this->xhtml_encode($this->globals('khxc_form.formid'));
$url           = $this->xhtml_encode($this->globals('khxc_form.url'));
$upload        = $this->globals('khxc_form.upload');
$required      = $this->globals('khxc_form.required');
$desc_has_tags = $this->has_tags($this->globals('khxc_form.description'));
$buttname      = $this->globals('khxc_form.submit_modify');
$disablewl     = $this->globals('khxc_settings.' . $app . '.disablewishlist');
$ns            = $this->globals('khxc.namespace');

if (empty($buttname)) {$buttname = 'Submit';}
else {$buttname = $this->xhtml_encode($buttname);}




$isaddtocart = 0;

if (preg_match('/\-\-prodaddtocart/',$formid)) {$isaddtocart = 1;}





$show_wl = 0;

if (preg_match('/\-\-prodaddtocart/',$formid)) {$show_wl = 1;}
if (!(empty($disablewl)))                       {$show_wl = 0;}

$method = 'post';

if (preg_match('/\-\-prodsearch/',$formid)) {$method = 'get';}
if (preg_match('/\-\-minisearch/',$formid)) {$method = 'get';}

if ($desc_has_tags) {

     $description  = $this->globals('khxc_form.description');

} else {

     $description  = $this->xhtml_encode($this->globals('khxc_form.description'));

} // End of if statement.

$eol          = $this->globals('khxc.eol');

if ($description) {

     if ($desc_has_tags) {

          print $description . $eol . $eol;

     } else {

          print '<p>' . $description . '</p>' . $eol . $eol;

     } // End of if statement.

} // End of if statement.

if (($required) && ($show_wl)) {

   print '                         ' . $eol . $eol;

} elseif ($required) {

     print '                             ' . $eol . $eol;

} else {

     print '<p>Click the \'' . $buttname . '\' button at the bottom of this form to proceed.</p>' . $eol . $eol;

} // End of if statement.

if ($upload) {

     print '<form action="' . $url . '" method="' . $method . '" id="' . $formid . '" enctype="multipart/form-data" >' . $eol . $eol;

} else {

     print '<form action="' . $url . '" method="' . $method . '" id="' . $formid . '">' . $eol . $eol;

} // End of if statement.



if ($ns == 'prodshow') {

if (empty($isaddtocart)) {

   print '</form><p><input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
   print $formid . '--SUBMIT" value="' . $buttname;
   print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
   print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" /></p>';

   print ' <p><input class="khxc_formbutton" type="submit" name="ns" id="';
   print $formid . '--CANCEL" value="Cancel" /></p><br />';

} else {

   print '<p><input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
   print $formid . '--SUBMIT" value="' . $buttname;
   print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
   print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

      if ($show_wl) {

         print ' <input class="khxc_formbutton" type="submit" name="WISHLIST" id="';
         print $formid . '--WISHLIST" value="Would Like To Purchase" /></p>';

     } // End of if statement.

} // End of if statement.

} // End of if statement.

?>


Note the two print lines, which have no content, - the content was removed because it was my own, customised, content. - Normally those two lines contain the information about all boxes with an asterisk - * - needing to be completed - so just put something to that effect in those lines (XHTML tags and CSS OK), then check it in your webstore, and all should be fine. Also, where the buttons are (towards the very end of the code), there should be no <br /> tags, as these will invalidate your layout (XML 1.0 strict).

...For the form_header.php it is also necessary to add the required $ns function, like so:

Code: Select all
<?php

    $app           = $this->globals('khxc_display.app');
    $form          = $this->xhtml_encode($this->globals('khxc_form.form'));
    $formid        = $this->xhtml_encode($this->globals('khxc_form.formid'));
    $url           = $this->xhtml_encode($this->globals('khxc_form.url'));
    $upload        = $this->globals('khxc_form.upload');
    $required      = $this->globals('khxc_form.required');
    $desc_has_tags = $this->has_tags($this->globals('khxc_form.description'));
    $buttname      = $this->globals('khxc_form.submit_modify');
    $disablewl     = $this->globals('khxc_settings.' . $app . '.disablewishlist');
    $ns            = $this->globals('khxc.namespace');


Next I modified form_footer.php, avoiding the removal of the code because, as with form_header.php, this file is not specific to the prodshow namespace and casually removing chunks of code from this file does horrible things to other, important, parts of the webstore...

Code: Select all
if ($ns != 'prodshow') {

if (($required) && ($show_wl)) {

   print '<p style="text-align: justify;">In order to proceed with your order please ensure that all fields marked with an asterisk
   - <span style="color: black; font-weight: bold;">*</span> - have been completed, then click the <strong>' . $buttname . '</strong> or <strong>Would
   Like To Purchase</strong> button if you have, or are planning on creating, an account and wish to add this item to a list for buying at a later
   date.</p><br />' . $eol . $eol;

} elseif ($required) {

   print '<p style="text-align: justify;">All required fields are marked with an asterisk - <span style="color: black; font-weight: bold;">*</span>. 
   Click the <strong>' . $buttname . '</strong> button at the bottom of this form to proceed.</p><br />' . $eol . $eol;

} else {

     print '<p>Click the <strong>' . $buttname . '</strong> button at the bottom of this form to proceed.</p><br />' . $eol . $eol;

} // End of if statement.

} // End of if statement.


if ($ns != 'prodshow') {

if (empty($isaddtocart)) {

     print '<br /><p style="padding: 0 0 0 10px;" /><input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
     print $formid . '--SUBMIT" value="' . $buttname;
     print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
     print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

     print ' <input class="khxc_formbutton" type="submit" name="ns" id="';
     print $formid . '--CANCEL" value="Cancel" /></p><br />';

} else {

     print '<input class="khxc_formbutton" type="submit" name="SUBMIT" id="';
     print $formid . '--SUBMIT" value="' . $buttname;
     print '" onclick="return DisableSubmit(\'' . $formid . '\');" ';
     print 'onkeypress="return DisableSubmit(\'' . $formid . '\');" />';

     if (empty($disablewl)) {

          print ' <input class="khxc_formbutton" type="submit" name="WISHLIST" id="';
          print $formid . '--WISHLIST" value="Would Like To Purchase" />';

     } // End of if statement.

} // End of if statement.

} // End of if statement.


I did come unstuck somewhat with the quantity box. - I am familiar with creating formfields in the database, but could not work out how to call the field from within a code block or, more problematically, how to make it a submit field and to make it submit to the correct places.

What I am implementing, instead, is a more streamlined layout with no quantity box*, so now a customer adds one of an item by clicking on the Add to Cart button, with options if need be, and then modifies the required quantities in the shopping basket area.

I would still be interested to know how I would have gone about implementing the quantity box in a new location, though, and whether it could be implemented outside of a form. - I don't need an indepth guide, but some pointers so I could get a test setup that works with the cart software would be fine, because I could then use that in further modifications to our webstore and for posting future modifications here that, hopefully, won't wreck other people's sites through pulling the wrong functions or making the wrong database calls... :D


*(Home > Hybrid X Core > Database: Connections, Backups and Raw Admin > Raw Database Admin - gbu0.prodaddtocart.quantity - type* TEXTBOX-SMALL to HIDDEN-REG for anyone else wanting to do likewise, with text edits/additions on product pages, etc. so customers know what's going on and that, yes, they can have more than one of a given item)
LDW
 
Posts: 17
Joined: 09 Aug 2010 18:48


Return to Store Design Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron
corner image
Valid XHTML   Valid CSS   w3c wai aa
GreenbarnWeb.com © 2001 - 2013
corner image