Atleast once a month I need to refund or adjust an order after Zen merges a customers saved and sessions carts during checkout. This is particularly bad with Express Checkout, which seems to give no indication it's done so, until you see your order while finalizing the payment.

This small change to "includes/modules/shopping-cart.php" changes the saved cart behaviour to the following:
  • if the user has no cart and no saved cart, do nothing
  • if the user has a saved cart, but no current cart, load the saved cart
  • if the user has a saved cart and a current cart, continue using the current cart


Basically, it means no surprises at checkout!

The changed section is the restore_contents() method as below:
PHP Code:
/**
   * Method to restore cart contents
   * AND HAS BEEN BASTERDIZED FROM IT'S ORIGINAL FORM!
   *
   * For customers who login, cart contents are also stored in the database.
   * {TABLE_CUSTOMER_BASKET et al}. This allows the system to remember the
   * contents of their cart over multiple sessions.
   * This method simply retrieve the content of the databse store cart
   * for a given customer. Note also that if the customer already has
   * some items in their cart before they login, we don't scew with their
   * cart; we only update the database with their cart contents (over writing
   * the old contents.)
   *
   * @return void
   * @global object access to the db object
   */
  
function restore_contents() {
    global 
$db;
    if (!
$_SESSION['customer_id']) return false;
    
$this->notify('NOTIFIER_CART_RESTORE_CONTENTS_START');
    
    
// insert current cart contents in database overtop of old contents
    
if (count($this->contents) > 0) {
      
reset($this->contents);
      
      
//blow away the old data
      
$sql "delete from " TABLE_CUSTOMERS_BASKET "
                where customers_id = '" 
. (int)$_SESSION['customer_id'] . "'";
      
$db->Execute($sql);
      
$sql "delete from " TABLE_CUSTOMERS_BASKET_ATTRIBUTES "
                where customers_id = '" 
. (int)$_SESSION['customer_id'] . "'";
      
$db->Execute($sql);
      
      
//save the new data
      
while (list($products_id, ) = each($this->contents)) {
        
//          $products_id = urldecode($products_id);
          
$qty $this->contents[$products_id]['qty'];

          
$sql "insert into " TABLE_CUSTOMERS_BASKET "
                                (customers_id, products_id, customers_basket_quantity,
                                 customers_basket_date_added)
                                 values ('" 
. (int)$_SESSION['customer_id'] . "', '" zen_db_input($products_id) . "', '" .
          
$qty "', '" date('Ymd') . "')";

          
$db->Execute($sql);

          if (isset(
$this->contents[$products_id]['attributes'])) {
            
reset($this->contents[$products_id]['attributes']);
            while (list(
$option$value) = each($this->contents[$products_id]['attributes'])) {

              
//clr 031714 udate query to include attribute value. This is needed for text attributes.
              
$attr_value $this->contents[$products_id]['attributes_values'][$option];
              
//                zen_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . zen_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . zen_db_input($attr_value) . "')");
              
$products_options_sort_orderzen_get_attributes_options_sort_order(zen_get_prid($products_id), $option$value);
              if (
$attr_value) {
                
$attr_value zen_db_input($attr_value);
              }
              
$sql "insert into " TABLE_CUSTOMERS_BASKET_ATTRIBUTES "
                                    (customers_id, products_id, products_options_id,
                                     products_options_value_id, products_options_value_text, products_options_sort_order)
                                     values ('" 
. (int)$_SESSION['customer_id'] . "', '" zen_db_input($products_id) . "', '" .
              
$option "', '" $value "', '" $attr_value "', '" $products_options_sort_order "')";

              
$db->Execute($sql);
            }
          }
      }
    } 
Cheers,
Spiffed