Jump to content
kymation

Xsell in Cart for Modular Shopping Cart (Responsive)

Recommended Posts

This addon shows an Xsell (Cross-Sell) box on the shopping cart page. It's based on the Xsell Addon and the Modular Shopping Cart BS Addon. All of this requires osCommerce Responsive (Bootstrap) version 2.3.4r Gold or later.

 

The module uses products that have been selected for cross-sell on the product(s) currently in the cart. The maximum number of products shown can be set, and the order in which they are shown (popularity or random) can be set.

 

The Addon is here.

 

Regards

Jim

Edited by kymation

See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Hi Kymation

 

I get error after install shopping_cart.php -

 table_products_xsell' doesn't exist

select xsell_id from TABLE_PRODUCTS_XSELL where products_id = 3

 

Something missing, pls halp


Getting the Phoenix off the ground

Share this post


Link to post
Share on other sites

@@Peper  Which Xsell addon do you have installed?

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

That's not what I asked you. Please read the User's Manual in that package.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

I'm using a different cross-sell contribution, Optional Related Products http://addons.oscommerce.com/info/8057

 

It was simple to change so that products show up in the module. In /public_html/edge/includes/modules/content/shopping_cart/cm_sc_xsell_in_cart.php change the following function

 protected function xsell_products( $ids_in_cart_array ) {
      global $cart;
      
      $xsell_contents_array = array();
      foreach ( $ids_in_cart_array as $product_id_in_cart ) {
        $xsell_query_raw = "
          select
            xsell_id
          from
            " . TABLE_PRODUCTS_XSELL . " 
          where 
            products_id = " . $product_id_in_cart . "
        ";
        //echo $xsell_query_raw;
        $xsell_query = tep_db_query( $xsell_query_raw );

        while( $xsell_products = tep_db_fetch_array( $xsell_query ) ) {
          if( !in_array( $xsell_products['xsell_id'], $xsell_contents_array ) && !$cart->in_cart( $xsell_products['xsell_id'] ) ) {
            $xsell_contents_array[] = (int) $xsell_products['xsell_id'];
          }
        }
      }

      $xsell_contents_list = implode( ',', $xsell_contents_array );
      return $xsell_contents_list;
    }

to:

protected function xsell_products( $ids_in_cart_array ) {
      global $cart;
      
      $xsell_contents_array = array();
      foreach ( $ids_in_cart_array as $product_id_in_cart ) {
        $xsell_query_raw = "
          select
            pop_products_id_slave
          from
            products_related_products 
          where 
            pop_products_id_master = " . $product_id_in_cart . "
        ";
        //echo $xsell_query_raw;
        $xsell_query = tep_db_query( $xsell_query_raw );

        while( $xsell_products = tep_db_fetch_array( $xsell_query ) ) {
          if( !in_array( $xsell_products['pop_products_id_slave'], $xsell_contents_array ) && !$cart->in_cart( $xsell_products['pop_products_id_slave'] ) ) {
            $xsell_contents_array[] = (int) $xsell_products['pop_products_id_slave'];
          }
        }
      }

      $xsell_contents_list = implode( ',', $xsell_contents_array );
      return $xsell_contents_list;
    }

It works perfectly, thank you @@kymation!


Let's make things easier for new osCommerce users http://forums.oscommerce.com/topic/402638-discussion-about-hard-coded-database-tables/?p=1718900  Getting there with osCommerce 2.4! :thumbsup:

Share this post


Link to post
Share on other sites

@@kymation

 

about the products id array, i tend to explode to an in list and have the result in one database round trip ...

all little things help I think ...


KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Share this post


Link to post
Share on other sites

@@frankl  I try to make these modules so that they can be easily modified. I'm pleased to know that I got it right on this one. Good work! Now please release your work as an Addon so that others can use it.

 

@@bruyndoncx  I'm not getting what you are talking about. Could you give me some sample code or some additional explanation? Any improvement to the database calls would be a good thing, so I want to learn.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

@@kymation

 

same principle, but a piece of code with categories, hope you understand what I'm getting at ...

$in_categories = $current_category_id ;
$in_subs = implode(',', $subcategories_array);
if ($in_subs !== '') $in_categories .= ',' . $in_subs;

...
		WHERE      p2c.categories_id IN (" . $in_categories . ")
...

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Share this post


Link to post
Share on other sites

I see now -- you're building the comma-separated list directly instead of first putting it in an array. That does save a step. Thanks for explaining this to me.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

@@kymation

 

Below code stops buy now for working when on index.php page - buy now buttons only works when in product page

 

If this code is commend out then all is fine except xsell prodcuts buynow is redirected to index page

Pls have a look

Find this:

      case 'buy_now' :        if (isset($_GET['products_id'])) {

REPLACE with this:

// BOF: XSell
      case 'buy_now' :        if (isset($_GET['product_to_buy_id'])) {
								if (tep_has_product_attributes($_GET['product_to_buy_id'])) {
								  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $_GET['product_to_buy_id']));
								} else {
								  $cart->add_cart($_GET['product_to_buy_id'], $cart->get_quantity($_GET['product_to_buy_id'])+1);
								}
                              } elseif (isset($_GET['products_id'])) {
// EOF: XSell

This is more code on application_top file

// Shopping cart actions
  if (isset($HTTP_GET_VARS['action'])) {
// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled
    if ($session_started == false) {
      tep_redirect(tep_href_link(FILENAME_COOKIE_USAGE));
    }

    if (DISPLAY_CART == 'true') {
      $goto =  FILENAME_SHOPPING_CART;
      $parameters = array('action', 'cPath', 'products_id', 'pid');
    } else {
      $goto = $PHP_SELF;
      if ($_GET['action'] == 'buy_now') {
// BOE: XSell
        if (isset($_GET['product_to_buy_id'])) {
          $parameters = array('action', 'pid', 'products_to_but_id');
		} else {
          $parameters = array('action', 'pid', 'products_id');
		}
// EOE: XSell
      } else {
        $parameters = array('action', 'pid');
      }
    }
    switch ($HTTP_GET_VARS['action']) {
      // customer wants to update the product quantity in their shopping cart
      case 'update_product' : $n=sizeof($HTTP_POST_VARS['products_id']);
                              for ($i=0; $i<$n; $i++) {
                                if (in_array($HTTP_POST_VARS['products_id'][$i], (is_array($HTTP_POST_VARS['cart_delete']) ? $HTTP_POST_VARS['cart_delete'] : array()))) {
                                  $cart->remove($HTTP_POST_VARS['products_id'][$i]);
                                  $messageStack->add_session('product_action', sprintf(PRODUCT_REMOVED, tep_get_products_name($HTTP_POST_VARS['products_id'][$i])), 'warning');
                                } else {
                                  $attributes = ($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]]) ? $HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]] : '';
                                  $cart->add_cart($HTTP_POST_VARS['products_id'][$i], $HTTP_POST_VARS['cart_quantity'][$i], $attributes, false);
                                }
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
      // customer adds a product from the products page
      case 'add_product' :    if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
                                $attributes = isset($HTTP_POST_VARS['id']) ? $HTTP_POST_VARS['id'] : '';
                                $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id'])) + $HTTP_POST_VARS['cart_quantity'], $HTTP_POST_VARS['id']);

                              }
                              $messageStack->add_session('product_action', sprintf(PRODUCT_ADDED, tep_get_products_name((int)$HTTP_POST_VARS['products_id'])), 'success');
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
      // customer removes a product from their shopping cart
      case 'remove_product' : if (isset($HTTP_GET_VARS['products_id'])) {
                                $cart->remove($HTTP_GET_VARS['products_id']);
                                $messageStack->add_session('product_action', sprintf(PRODUCT_REMOVED, tep_get_products_name($HTTP_GET_VARS['products_id'])), 'warning');
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
      // performed by the 'buy now' button in product listings and review page
//      case 'buy_now' :        if (isset($HTTP_GET_VARS['products_id'])) {
// BOF: XSell
      case 'buy_now' :        if (isset($HTTP_GET_VARS['products_id'])) {
//								if (tep_has_product_attributes($HTTP_GET_VARS['product_to_buy_id'])) {
//								  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['product_to_buy_id']));
//								} else {
//								  $cart->add_cart($HTTP_GET_VARS['product_to_buy_id'], $cart->get_quantity($HTTP_GET_VARS['product_to_buy_id'])+1);
//								}
//                              } elseif (isset($HTTP_GET_VARS['products_id'])) {
// EOF: XSell
                                if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) {
                                  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id']));
                                } else {
                                  $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1);
                                  $messageStack->add_session('product_action', sprintf(PRODUCT_ADDED, tep_get_products_name((int)$HTTP_GET_VARS['products_id'])), 'success');
                                }
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
      case 'notify' :         if (tep_session_is_registered('customer_id')) {
                                if (isset($HTTP_GET_VARS['products_id'])) {
                                  $notify = $HTTP_GET_VARS['products_id'];
                                } elseif (isset($HTTP_GET_VARS['notify'])) {
                                  $notify = $HTTP_GET_VARS['notify'];
                                } elseif (isset($HTTP_POST_VARS['notify'])) {
                                  $notify = $HTTP_POST_VARS['notify'];
                                } else {
                                  tep_redirect(tep_href_link($PHP_SELF, tep_get_all_get_params(array('action', 'notify'))));
                                }
                                if (!is_array($notify)) $notify = array($notify);
                                $n=sizeof($notify);
                                for ($i=0; $i<$n; $i++) {
                                  $check_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . (int)$notify[$i] . "' and customers_id = '" . (int)$customer_id . "'");
                                  $check = tep_db_fetch_array($check_query);
                                  if ($check['count'] < 1) {
                                    tep_db_query("insert into " . TABLE_PRODUCTS_NOTIFICATIONS . " (products_id, customers_id, date_added) values ('" . (int)$notify[$i] . "', '" . (int)$customer_id . "', now())");
                                  }
                                }
                                $messageStack->add_session('product_action', sprintf(PRODUCT_SUBSCRIBED, tep_get_products_name((int)$HTTP_GET_VARS['products_id'])), 'success');
                                tep_redirect(tep_href_link($PHP_SELF, tep_get_all_get_params(array('action', 'notify'))));
                              } else {
                                $navigation->set_snapshot();
                                tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
                              }
                              break;
      case 'notify_remove' :  if (tep_session_is_registered('customer_id') && isset($HTTP_GET_VARS['products_id'])) {
                                $check_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and customers_id = '" . (int)$customer_id . "'");
                                $check = tep_db_fetch_array($check_query);
                                if ($check['count'] > 0) {
                                  tep_db_query("delete from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and customers_id = '" . (int)$customer_id . "'");
                                }
                                $messageStack->add_session('product_action', sprintf(PRODUCT_UNSUBSCRIBED, tep_get_products_name((int)$HTTP_GET_VARS['products_id'])), 'warning');
                                tep_redirect(tep_href_link($PHP_SELF, tep_get_all_get_params(array('action'))));
                              } else {
                                $navigation->set_snapshot();
                                tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
                              }
                              break;
      case 'cust_order' :     if (tep_session_is_registered('customer_id') && isset($HTTP_GET_VARS['pid'])) {
                                if (tep_has_product_attributes($HTTP_GET_VARS['pid'])) {
                                  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['pid']));
                                } else {
                                  $cart->add_cart($HTTP_GET_VARS['pid'], $cart->get_quantity($HTTP_GET_VARS['pid'])+1);
                                }
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
    }
  }

// include the who's online functions

Getting the Phoenix off the ground

Share this post


Link to post
Share on other sites

Never mind, solved

      // performed by the 'buy now' button in product listings and review page
//      case 'buy_now' :        if (isset($HTTP_GET_VARS['products_id'])) {
// BOF: XSell
      case 'buy_now' :        if (isset($HTTP_GET_VARS['products_id'])) {
								if (tep_has_product_attributes($HTTP_GET_VARS['product_to_buy_id'])) {
								  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['product_to_buy_id']));
								} else {
								  $cart->add_cart($HTTP_GET_VARS['product_to_buy_id'], $cart->get_quantity($HTTP_GET_VARS['product_to_buy_id'])+1);
								}
                             
// EOF: XSell
                                if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) {
                                  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id']));
                                } else {
                                  $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1);
                                  $messageStack->add_session('product_action', sprintf(PRODUCT_ADDED, tep_get_products_name((int)$HTTP_GET_VARS['products_id'])), 'success');
                                }
                              }
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;

Getting the Phoenix off the ground

Share this post


Link to post
Share on other sites

@@Peper  Your posts appear to refer to one of the Xsell addons and not this module. Please add your comments to the support thread for the correct Addon so that others can find them. Or refer them here if you want.

 

Thank you for posting the solution to the problem you found.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Hi, this funcion is correct?

    protected function xcell_product_data_query( $xsell_contents_list ) {
      $xsell_contents_array = array();

xcell or xsell?

Regards


No external links here, thank you

Share this post


Link to post
Share on other sites

I missed this comment somehow. Sorry for being so slow.

 

The call to the function is spelled the same way, so everything works just fine. However, it's inconsistent with the rest of the module, so the spelling really should be changed both places.

 

Thanks for bringing that to my attention.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×