Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Products & shopping cart


Recommended Posts

if today a  offer is released and a customer this in the basket you put this offer but tomorrow deactivates this product remains in the basket and the customer can still buy this after some time, although in the shop this is no longer to be found. In order to remove these offers from the cart that are deactivated and the customer can no longer buy them, the class must be changed a bit. applies to all versions.

catalog/includes/classes/shopping_cart.php

Find:
// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");


Change to:
// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "' and products_status = 1");



Find:
      $products_array = array();
      foreach(array_keys($this->contents) as $products_id) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_baseprice, p.products_deposit, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");


Change to:
      $products_array = array();
      foreach(array_keys($this->contents) as $products_id) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_baseprice, p.products_deposit, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_status = 1");

 

Link to comment
Share on other sites

Nice catch.

However, removing the product from the basket abruptly without first informing the customer may be a little rude, don't you think so?

The right approach should be to check the basket for any item that is no longer available, then "grey-out" the item in the cart listing, and then provide a little note saying the item is no longer available and has been removed from the basket. I believe this method is more graceful.

Just my thought and I am hoping some good programmer will write the code. 😊

Link to comment
Share on other sites

bug fix

Find:
// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");


Change to:
// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "' and products_status = 1");



Find:
      $products_array = array();
      foreach(array_keys($this->contents) as $products_id) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");


Change to:
      $products_array = array();
      foreach(array_keys($this->contents) as $products_id) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_status = 1");

 

Link to comment
Share on other sites

I did this to the cm_sc_product_listing.php:

Quote

        for ($i=0, $n=sizeof($products); $i<$n; $i++) {

          $not_avail = '';
          // Check product status
          $status_query = tep_db_query("select products_status from products where products_id = '" . (int)$products[$i]['id'] . "'");
          $p_status = tep_db_fetch_array($status_query);
          if ($p_status['products_status'] < 1) {
            $not_avail = 'Sorry, this product is no longer available in our store<br>and hence has been removed from the cart';
            $products_name .= '<tr class="bg-secondary">';
            $products_name .=   '<td class="d-none d-md-table-cell">' . tep_image('images/' . $products[$i]['image'], htmlspecialchars($products[$i]['name']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</td>';
            $products_name .=   '<td><del>' . $products[$i]['name'] . ' [' . $products[$i]['model'] .']</a></td><td colspan="4">(' . $not_avail . ')</del></td></tr>';
            $cart->remove($products[$i]['id']);
         } else {

 .... (normal product listing) .....

        }

 

Link to comment
Share on other sites

here a little better solution. Once an offer is deactivated, the price is automatically set to the regular value

testing only for EDGE

<?php 

catalog/includes/classes/shopping_cart.php 


Find:

// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
        if ($product = tep_db_fetch_array($product_query)) {
          $prid = $product['products_id'];
          $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
          $products_price = $product['products_price'];
          $products_weight = $product['products_weight'];

          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows ($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }

          $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
          $this->weight += ($qty * $products_weight);



Change to:

// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight, products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
        if ($product = tep_db_fetch_array($product_query)) {
if ($products['products_status'] == 0){
          $prid = $product['products_id'];
          $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
          $products_price = $product['products_price'];
          $products_weight = $product['products_weight'];
}else{
          $prid = $product['products_id'];
          $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
          $products_price = $product['products_price'];
          $products_weight = $product['products_weight'];
          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows ($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }
}
          $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
          $this->weight += ($qty * $products_weight);

#####################################################

Find:

      $products_array = array();
      foreach(array_keys($this->contents) as $products_id) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
        if ($products = tep_db_fetch_array($products_query)) {
          $prid = $products['products_id'];
          $products_price = $products['products_price'];

          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }



Change to:

      $products_array = array();
      foreach(array_keys($this->contents) as $products_id) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_status, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");

        if ($products = tep_db_fetch_array($products_query)) {
if ($products['products_status'] == 0){
          $prid = $products['products_id'];
          $products_price = $products['products_price'];
}else{
          $prid = $products['products_id'];
          $products_price = $products['products_price'];
          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }
}

#####################################################

Find:

          $products_array[] = array('id' => $products_id,
                                    'name' => $products['products_name'],
                                    'model' => $products['products_model'],
                                    'image' => $products['products_image'],
                                    'price' => $products_price,
                                    'quantity' => $this->contents[$products_id]['qty'],
                                    'weight' => $products['products_weight'],
                                    'final_price' => ($products_price + $this->attributes_price($products_id)),
                                    'tax_class_id' => $products['products_tax_class_id'],
                                    'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));

Change to:

          $products_array[] = array('id' => $products_id,
                                    'name' => $products['products_name'],
                                    'model' => $products['products_model'],
                                    'image' => $products['products_image'],
                                    'price' => $products_price,
                                    'quantity' => $this->contents[$products_id]['qty'],
                                    'weight' => $products['products_weight'],
                                    'status' => $products['products_status'],
                                    'final_price' => ($products_price + $this->attributes_price($products_id)),
                                    'tax_class_id' => $products['products_tax_class_id'],
                                    'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));

#####################################################


catalog/shopping_cart.php 


Find:

      $products_name .= '</td>';
      $products_name .= '</td></strong><td align="right" valign="top"><strong>' . TEXT_TODAY_NON_AVALIABLE . ' ' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</strong></td>' .
                        '</tr>';

Change to:

if ($products[$i]['status'] == 0){
      $products_name .= '</td>';
      $products_name .= '</td></strong><td align="right" valign="top"><strong>' . TEXT_TODAY_NON_AVALIABLE . ' ' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</strong></td>' .
                        '</tr>';
}else{
      $products_name .= '</td>';
      $products_name .= '</td></strong><td align="right" valign="top"><strong>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</strong></td>' .
                        '</tr>';
}

#####################################################

catalog/checkout_confirmation.php

Find:

  for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {

Add after:

  	$product_info_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$order->products[$i]['id'] . "'");
    $product_info = tep_db_fetch_array($product_info_query);

Find:

    echo '</td>' . "\n";
    echo '<td align="right" valign="top"><br>' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $pls_taxinfo . '</td>' . "\n" .
         '</tr>' . "\n";

Change to:

if ($product_info['products_status'] == 0){
    echo '</td>' . "\n";
    echo '<td align="right" valign="top"><br>' . TEXT_TODAY_NON_AVALIABLE . ' ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . '</td>' . "\n" .
         '</tr>' . "\n";
}else{
    echo '</td>' . "\n";
    echo '<td align="right" valign="top"><br>' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . '</td>' . "\n" .
         '</tr>' . "\n";
}


#####################################################

catalog/includes/languages/english.php

Add:

define('TEXT_TODAY_NON_AVALIABLE', 'No offer available today ');

 

Link to comment
Share on other sites

1 minute ago, JcMagpie said:

No such thing is sales, see it as an opportunity to talk with your customer you could offer an alternative.

At times, it is best not to annoy a customer. I do come across customers who are picky and easily annoyed.

Link to comment
Share on other sites

vor 1 Stunde schrieb JcMagpie:

This is not new! it's been like this for a looooooooong time and I have never ever had a cart with problem. Even official 2.3.4.1 is the same....

I would rather make a late offer sale than no sale! 

I'm curious if 30 or 40 customers have such an offer in the cart and buy it later at a later date although this is no longer available. Do you pay then to make your customers happy?

Link to comment
Share on other sites

A customer is a customer just be glad you have one  :), you will find many users have set the site to allow purchase of out of stock item. So having a offer sale after the offer is over is no big issue, but it's up to each buissness to do what they think is best for them.

Me I don't mind, a sale is a sale on time or not.

 

Link to comment
Share on other sites

It is already available for Phoenix, but I think it's not the solution to the original problem, this is refering to someone adding a product on special offer to cart when offer close date is not expired but not checking out. Then other customers buy last stock of offer and offer is closed then original customer comes back to his account uses saved cart and checks out.

Do you take his order after offer is expired or not? or do you auto deleat offer product from cart?

image.png.567a9a14d6eb054f7e41ec6b15a437f6.png

 

Link to comment
Share on other sites

The product need not necessarily be a special offer. It can be any product. Today you decide to deactivate the product because you do not plan to sell it anymore. It may just happen that it is already placed in the shopping carts of  a number of customers. So how do you deal with this situation? I would think you should apologize to keep the customers happy. This method of handling is practised in Amazon and Taobao and the accident happen s all the time.

Link to comment
Share on other sites

33 minutes ago, kgtee said:

I would think you should apologize to keep the customers happy

I agree 100% with you. This is why you should install and run unsold carts report every day. This way you avoid problems and have an opertunity to contact customers if needed.

Every buissness needs to do what they feel is right for them so which ever solution you select it's right for you.

 

Link to comment
Share on other sites

Just tested on Phoenix 1.0.3.0 and,

1) For special offers when customer returns to his old cart he will see the product at it's normal price and it's up to him to buy or remove the item at the new price. So no real problem with this.

2) For out of stock ( if you have do not allow  checkout for zero stock enabled)  when customer returns to his old cart he will see the product is clearly marked as out of stock. Again he can continue with out it or not.

So looks as if all cases are already coverd by the code.

 

Link to comment
Share on other sites

The point is that if I have a product that is only once in the week as an offer that can only be bought on this one day as an offer. That's exactly how customers come to the shop on this particular day. For this reason, this article must also automatically as an offer when you deactivate the normal price without having to rummage through the offers to this one to disable

The product is always in stock and also available. only the status between normal price and offer changes weekly.

something cleaner in the shopping_cart.php class

Find:

// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
        if ($product = tep_db_fetch_array($product_query)) {
          $prid = $product['products_id'];
          $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
          $products_price = $product['products_price'];
          $products_weight = $product['products_weight'];

          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows ($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }

          $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
          $this->weight += ($qty * $products_weight);



Change to:

// products price
        $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
        if ($product = tep_db_fetch_array($product_query)) {
          $prid = $product['products_id'];
          $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
          $products_price = $product['products_price'];
          $products_weight = $product['products_weight'];

          $specials_query = tep_db_query("select s.specials_new_products_price from " . TABLE_SPECIALS . " s, " . TABLE_PRODUCTS . " p where p.products_id = s.products_id and s.products_id = '" . (int)$prid . "' and s.status = '1' and p.products_status = '1'");
          if (tep_db_num_rows ($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }
          $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
          $this->weight += ($qty * $products_weight);

#####################################################

Find:

      $products_array = array();
      foreach(array_keys($this->contents) as $products_id) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
        if ($products = tep_db_fetch_array($products_query)) {
          $prid = $products['products_id'];
          $products_price = $products['products_price'];

          $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
          if (tep_db_num_rows($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }



Change to:

      $products_array = array();
      foreach(array_keys($this->contents) as $products_id) {
        $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");

        if ($products = tep_db_fetch_array($products_query)) {
          $prid = $products['products_id'];
          $products_price = $products['products_price'];

          $specials_query = tep_db_query("select s.specials_new_products_price from " . TABLE_SPECIALS . " s, " . TABLE_PRODUCTS . " p where p.products_id = s.products_id and s.products_id = '" . (int)$prid . "' and s.status = '1' and p.products_status = '1'");
          if (tep_db_num_rows($specials_query)) {
            $specials = tep_db_fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }

 

Link to comment
Share on other sites

Now I need some help with the products_id. Why is the same product, which has been put into the shopping cart several times, always filed as a single article? it's about the count generated for attributes. same product same attributes and each other id?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...