elegant way needed to show (and buy) products with status = 0 (on special circumstances)

Open to all! Ask other shopowners for help.
Post Reply
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

elegant way needed to show (and buy) products with status = 0 (on special circumstances)

Post by loop »

Hi All
i need a way to can show on product_info.php a products_id which is status = 0 (on a special circumstances, for example if they come with a special link / Parameter)

i can make in the product_info.php this, but the "$products" object / array is not really filled whenn status=0 so i get errors on every corner. So i need to have a better way / hook maybe to do that, can anybody point me to the right direction?

Code: Select all

if((!empty($_GET['ad']) && strpos($_GET['ad'],Speciallink_') > -1)||(!empty($advertiser) && strpos($advertiser,'Speciallink_') > -1)){	
    $show_status_red = "";
  }else{
    $show_status_red = "p.products_status = '1' and";
  } 
  
  $product_info_query = tep_db_query("SELECT p.*, pd.* FROM products p, products_description pd where ".$show_status_red." p.products_id = " . (int)$_GET['products_id'] . " and pd.products_id = p.products_id and pd.language_id = " . (int)$languages_id);


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: elegant way needed to show (and buy) products with status = 0 (on special circumstances)

Post by burt »

It's a difficult concept, as status = 0 means (for most shopowners) the product is unavailable, but may come back at some later date.

I'd probably make a new product_info page to display these particular products.
EG product_discontinued.php [or whatever name you think up]
In this page simply show products where p.products_status = 0 [as you would not want your live products showing on this particular page.

Conceptual difficulties.
Will the breadcrumb work?
Will the (hidden) product data work? EG twitter stuff, opengraph, etc
Will the customer be able to add a status=0 product to cart?
Will the checkout work?

It's all unknown, as no one (I think) will have used the products_status in this way.
My advice would be to set up a new product displaying page to at least get a status=0 product showing, and then further test things from there...
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: elegant way needed to show (and buy) products with status = 0 (on special circumstances)

Post by Kofod95 »

I might investigate something similar with the working-title: Pseudo products.
This is intended for plastic bags and special gift wrapping items to offer on the shopping cart.
As Burt, I would think using product info may be too much wrestling with intended behavior, so a new page for that would likely be easier. You may be able to pull the product info layout anyway, and maybe even create the product as normal. I just noticed this check: https://github.com/CE-PhoenixCart/Phoen ... id.php#L33. Not sure how to implement, but seems possible

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: elegant way needed to show (and buy) products with status = 0 (on special circumstances)

Post by ecartz »

To fetch a product with status 0, try

Code: Select all

class hook_shop_product_info_ad {

  public function listen_siteWideStart() {
    if (!isset($GLOBALS['product']) && !empty($_GET['ad') && (strpos($_GET['ad'], 'Speciallink_') !== false)) {
      $GLOBALS['product'] = product_by_id::administer($_GET['products_id']);
      $GLOBALS['product']->set('status', '1');
    }
  }

}
But it might be easier to work from the other end. Instead of making the product status 0, put something else in that tells you that when ad is not set, make the product unbuyable. That's two hooks. One that blocks add_to_cart on unbuyable products and another that blocks checkout or the cart_order_builder on unbuyable products. If you put a hook in checkout, you might have it replace the stock check.
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: elegant way needed to show (and buy) products with status = 0 (on special circumstances)

Post by Kofod95 »

For ecartz' proposal I have something similar I know I need to do, though I will not hide the products completely, only their buttons.
If I get to it before you, I'll gladly assist you with the experience gained from that!

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: elegant way needed to show (and buy) products with status = 0 (on special circumstances)

Post by loop »

thank you all!
Good points, and i already implemented it with the ideas given. I made a addititional field in products called products_visible (standard = 1)
if i change the field to 0 it's not anymore in the queries i have in index.php and in search. but with the direct link to the product you can see it normaly and buy it normaly. So it's a "hidden" product which is normal handled as soon as it's found. for me it's perfect. The only thing i had to adjust alot of queries where "products_statuts = 1" its now "products_visible = 1 and products_status = 1"

thank you all for the perfect help / support


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply