X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Add to Cart Popup | Backporting to 4.4.X (https://forum.x-cart.com/showthread.php?t=64908)

totaltec 09-20-2012 07:01 AM

Add to Cart Popup | Backporting to 4.4.X
 
I think one of the juiciest features of 4.5.X is the addition of the new Add_to_cart_popup module. It is the best of both worlds. Traditionally you have to choose whether you want to redirect to cart and possibly lose out on additional impulse buying, or keep them on page with the ajax cart update and potentially confuse your visitor about whether the item is added or not. I have seen most of the bigger brands out there adopt this popup method. It also gives you an option for upselling.

So what do users with 4.4.X do? Upgrade their highly customized carts? No longer! 8)

I have been contracted to backport this module to a 4.4.4 site, and I am going to track my progress and steps in this thread. Stay tuned!

totaltec 09-20-2012 07:08 AM

Re: Add to Cart Popup | Backporting to 4.4.X
 
Step 1
Download a 4.5.X distribution from your Qualiteam helpdesk. We need to get the files for the module.

The two folders you are looking for are:
/modules/Add_to_cart_popup/
and
/skin/common_files/modules/Add_to_cart_popup/

Copy the contents of these two folders and place them in your xcart directory, being sure to keep the paths and folder structure intact.

While you are at it, grab this file too: /include/func/func.minicart.php

It helps if you create a folder on your computer that mimics the site structure and contains all the new files and the ones we are going to edit in the next step. This will let you upload all your changes to your dev site in one step, and after testing you can do the same for your live site.

totaltec 09-20-2012 07:16 AM

Re: Add to Cart Popup | Backporting to 4.4.X
 
Step 2
Now we are going to edit some files, to include the module functionality in the existing PHP files and templates. Be sure to create a backup of the existing file before you edit it. I like to name my backup files something meaningful like filename.extension.bak.Add_to_cart_popup so I can identify what I was doing when I edited that file.

Edit /cart.php:
Find:
PHP Code:

func_register_ajax_message(
        
'cartChanged',
        array(
            
'changes'     => array(
                
$result['productindex'] => array(
                    
'productid' => $add_product['productid'],
                    
'quantity'  => $result['quantity'],
                    
'changed'   => $result['changed'],
                )
            ),
            
'isEmpty' => empty($cart['products']) && empty($cart['giftcerts']),
            
'status'  => $result['status'],
        )
    ); 


After add:
PHP Code:

if (!empty($active_modules['Add_to_cart_popup'])) { 
        
func_add_to_cart_popup($productid$add_product$result['productindex']); 
    } 


Before:
PHP Code:

// Redirect
    
if (
        
$config['General']['redirect_to_cart'] == 'Y'
        
|| isset($_GET['redirect_to_cart'])
    ) 

Edit /include/data_cache.php:
Find:
PHP Code:

function func_sort_active_modules($a$b)
{
    static 
$sort_order = array(
        
'Discount_Coupons' => 1#independent module 

After add:
PHP Code:

'Add_to_cart_popup' => 1#independent module 

Before:
PHP Code:

'Egoods' => 1#independent module 

Note: It doesn't seem to matter where in the list this snippet gets placed and editing this file may not be completely necessary, I'm just being careful to copy the 4.5.X code here.

Edit /include/product_modify.php:
Find:
PHP Code:

if (!empty($active_modules['Recommended_Products'])) {
            
func_refresh_product_rnd_keys($productid);
        } 

Change it to:
PHP Code:

if (
            !empty(
$active_modules['Recommended_Products'])
            || !empty(
$active_modules['Add_to_cart_popup'])
        ) {
            
func_refresh_product_rnd_keys($productid);
        } 

Edit /include/func/func.product.php:
Find:
PHP Code:

// Generate ORDER BY rule

    
if (empty($orderby)) {

        
$orderby $config['Appearance']['products_order']
            ? 
$config['Appearance']['products_order']
            : 
'orderby';

        if (!empty(
$orderby_rules))
            
$orderby $orderby_rules[$orderby];
    
    } 

After add:
PHP Code:

elseif ($orderby == 'skip_orderby') {
        
$orderby '';
    } 

Before:
PHP Code:

// Initialize service arrays 

Edit /skin/common_files/customer/service_js.tpl:
Find:
HTML Code:


{include file="onload_js.tpl"}

{if $config.UA.browser eq "MSIE"}
  {assign var=ie_ver value=$config.UA.version|string_format:'%d'}
  {if $ie_ver lt '7'}
    {load_defer file="customer/iefix.js" type="js"}
  {/if}
{/if}

After add:
HTML Code:


{if $active_modules.Add_to_cart_popup ne ''} 
  {load_defer file="modules/Add_to_cart_popup/product_added.js" type="js"}
{/if}

Note: You may need to make this change in your custom skin directory, check your skin and see if this file exists. Even if it doesn't you can create it there, and copy the contents of the common_files tpl before making the change. I like this as it keeps your changed templates in your custom skin folder for easy identification later.

totaltec 09-20-2012 09:36 AM

Re: Add to Cart Popup | Backporting to 4.4.X
 
1 Attachment(s)
Step 3
Now we need to update the database with the module settings and added language variables. To do this visit Tools > Patch/Upgrade section of your X-cart admin. Look under the heading "Apply SQL Patch".

In the text box labeled SQL query(ies) paste these queries:

INSERT INTO xcart_config VALUES ('enable_upselling','Upselling products','Show_Both','Add_to_cart_popup',10,'sele ctor','Show_Both','Show_Random:lbl_show_randomly_s elected_products\nShow:lbl_show_upselling_products \nShow_Both:lbl_show_upselling_and_random\nHide:lb l_do_not_show_upselling_products','');
INSERT INTO xcart_modules VALUES (98,'Add_to_cart_popup','This module allows your customers to see what they have added to cart along with upselling products.','Y');
INSERT INTO xcart_languages VALUES ('en','module_name_Add_to_cart_popup','Add To Cart Popup','Modules');
INSERT INTO xcart_languages VALUES ('en','lbl_show_upselling_and_random','Show upselling + random products','Labels');
INSERT INTO xcart_languages VALUES ('en','lbl_show_randomly_selected_products','Show random products','Labels');
INSERT INTO xcart_languages VALUES ('en','lbl_show_upselling_products','Show upselling products','Labels');
INSERT INTO xcart_languages VALUES ('en','lbl_do_not_show_upselling_products','Do not show additional products','Labels');
INSERT INTO xcart_languages VALUES ('en','lbl_item_added_to_cart','item added to cart','Labels');
INSERT INTO xcart_languages VALUES ('en','lbl_items_added_to_cart','items added to cart','Labels');
INSERT INTO xcart_languages VALUES ('en','lbl_proceed_to_checkout','Proceed to checkout','Labels');

Alternatively you can use phpMyAdmin for this task, or download the file attached to this post and upload it using the "Patch File" Upload button. (you may need to rename it to .sql instead of .txt, not sure haven't tried it yet)

totaltec 09-20-2012 02:22 PM

Re: Add to Cart Popup | Backporting to 4.4.X
 
You're Done!

You may want to run yoursite.com/cleanup.php. Now you can go to Settings > Modules and you should see Add To Cart Popup at the top of the list. If you don't then you might have forgotten to run the sql patch above.

Good luck, hope it helps. Mike White, signing off... :-)

ADDISON 09-20-2012 11:42 PM

Re: Add to Cart Popup | Backporting to 4.4.X
 
Great job Mike. Keep going!

Toora Designs 09-21-2012 11:49 AM

Re: Add to Cart Popup | Backporting to 4.4.X
 
Very nice Mike and thank you! Going to bookmark this thread :)

carlisleglass 10-22-2012 03:21 AM

Re: Add to Cart Popup | Backporting to 4.4.X
 
Excellent :)

Just make sure "Redirect customer to cart after adding a product" (Setting/General) is switched off, or you'll never see the popup! Took me about 15 minutes to work that one out :)

carpeperdiem 10-30-2012 05:24 AM

Re: Add to Cart Popup | Backporting to 4.4.X
 
Quote:

Originally Posted by carlisleglass
Excellent :)

Just make sure "Redirect customer to cart after adding a product" (Setting/General) is switched off, or you'll never see the popup! Took me about 15 minutes to work that one out :)


I'm using 4.5.3 gold plus and this switch caused me 12+ hours of insanity.

see: http://forum.x-cart.com/showthread.php?t=65209

THANK YOU for pointing this out!!!

I have been searching the forum in every way, and this did not show up. :-(

GEEZ -- turning this switch OFF should be a FRONT AND CENTER WARNING in the Add To Popup documentation, you think? If this switch is set, the module will not function. Hopefully, this thread helps someone searching.

For the search engines:

Add To Cart Popup
Not Working
Redirect customer to cart after adding a product setting

THANK YOU, THANK YOU THANK YOU!!!

stagshop 01-24-2013 06:59 PM

Re: Add to Cart Popup | Backporting to 4.4.X
 
I hope someone is still paying attention to this thread. I'm currently trying to modify products_t.tpl to remove all the <table> related tags so I can use <div> tags instead. If I do this, clicking the Buy Now button will add products to the cart, but the Add To Cart popup box no longer open. It seems that the popup module relies on <table> codes? Anyone have any insight as to why this might be, and better yet, which other files I need to modify?


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

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.