Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

no stock button in product_info


ce7

Recommended Posts

Hi

I have phoenix 1075 version, tried to make the buy button disable if it is no stock, the card product and product listing has show the button without problem, but I can not make the product information buy product to change, here is the code,

  if ( tep_get_products_stock($product_info['products_id']) > 0 ) {      
  echo tep_draw_button(MODULE_CONTENT_PI_BUY_BUTTON_TEXT, 'fas fa-shopping-cart', null, 'primary', array('params' => 'data-has-attributes="' . (($products_attributes['total'] > 0) ? '1' : '0') . '" data-in-stock="' . (int)$product_info['products_quantity'] . '" data-product-id="' . (int)$product_info['products_id'] . '"'), 'btn-success btn-block btn-lg btn-product-info btn-buy');
  } else {
  echo tep_draw_button(MODULE_CONTENT_PI_BUY_BUTTON_OUT_OF_STOCK, 'fas fa-ban', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . (int)$product_info['products_id']), NULL, array('params' => 'data-has-attributes="' . ((tep_has_product_attributes((int)$product_info['products_id']) === true) ? '1' : '0') . '" data-in-stock="' . (int)$product_info['in_stock'] . '" data-product-id="' . (int)$product_info['products_id'] . '"'), 'btn-danger btn-sm btn-product-listing btn-buy disabled') . PHP_EOL;
  }  

any help or suggestion to correctly change buy button to no stock button is appreciated, thanks!
image.png.d95a4eed07d81f27d7dbe4b07b684c75.pngimage.png.17b5f34ebc5b3c2b5f02d4d9abe59d29.pngimage.png.37b8a3203370c433c635d5b4e28efb88.png

Link to comment
Share on other sites

Note that the buy button can be shown either by a content module or by a PI module.  First check that you are editing the right one.  If you can't make any text appear when editing the template, you are probably editing the wrong one.  So either switch the location where you change the code or change which shows the buy button. 

Always back up before making changes.

Link to comment
Share on other sites

hi Matt, @ecartz

Thank you so much for your prompt reply.

Never notice that has another pi in the modules, thank you for the information, i will check it now.

(another question, is this pi controllable at admin/modules make it true or false, as I can only see the content one, but can not see the pi, does it mean i need to delete it or just also modify it?

 

Link to comment
Share on other sites

hi Matt, @ecartz

I just tried to modify the pi with the code:

  if ( tep_get_products_stock($product_info['products_id']) > 0 ) {
      echo tep_draw_button(PI_BUY_BUTTON_TEXT, '', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'products_id', 'sort', 'cPath')) . 'action=buy_now&products_id=' . (int)$product_info['products_id']), NULL, array('params' => 'data-has-attributes="' . $has_attributes . '" data-in-stock="' . (int)$product_info['in_stock'] . '" data-product-id="' . (int)$product_info['products_id'] . '"'), 'btn-light btn-product_info btn-buy') . PHP_EOL;
  } else {
      echo tep_draw_button(PI_BUY_BUTTON_OUT_OF_STOCK, 'fas fa-ban', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . (int)$product_info['products_id']), NULL, array('params' => 'data-has-attributes="' . ((tep_has_product_attributes((int)$product_info['products_id']) === true) ? '1' : '0') . '" data-in-stock="' . (int)$product_info['in_stock'] . '" data-product-id="' . (int)$product_info['products_id'] . '"'), 'btn-danger btn-sm btn-product_info btn-buy disabled') . PHP_EOL;
  }

[/php]

and this is the result i got:

Error!

Unable to determine the page link!

Link to comment
Share on other sites

I tried JcM code for no stock, which is working with button disable, but the overlay for add to cart will not show properly, i dont know how to modify the java code, that is why i am trying to modify the no stock for each module files, all working except the product information button....
image.png.f650b89b4451ea77dedfbbc7b971f965.png  image.png.43061795dc59b20254c26cd3eca87b31.png

Link to comment
Share on other sites

Hi,

I have created the following add-ons for the PI system that should help -

1. An Add to Cart button that has a test for a minimum stock level - based on the Buy Button code.
2. An Out of Stock message that also has a test for a minimum stock level - based on the Product Model code.


In addition update the code in the following files to make the same test against the minimum stock level - this is for the product listing cards;
 

1. in "includes\languages\english.php"

add the line

 

const PRODUCT_OUT_OF_STOCK = 'Out of Stock';


 2. in "\templates\default\includes\components\product_listing.php" (around line 132)

            replace 

if ($has_attributes == 0) $prod_list_contents .= tep_draw_button(IS_PRODUCT_BUTTON_BUY, '', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . (int)$listing['products_id']), NULL, array('params' => 'data-has-attributes="' . $has_attributes . '" data-in-stock="' . (int)$listing['in_stock'] . '" data-product-id="' . (int)$listing['products_id'] . '"'), 'btn-light btn-product-listing btn-buy') . PHP_EOL;

            with

 

if ($has_attributes == 0) {
  if ((int)$listing['in_stock'] > MAX_OUT_OF_STOCK) {
     $prod_list_contents .= tep_draw_button(IS_PRODUCT_BUTTON_BUY, '', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . (int)$listing['products_id']), NULL, array('params' => 'data-has-attributes="' . $has_attributes . '" data-in-stock="' . (int)$listing['in_stock'] . '" data-product-id="' . (int)$listing['products_id'] . '"'), 'btn-light btn-product-listing btn-buy') . PHP_EOL;
   } else {
     $prod_list_contents .= '<span style="background:#F8D7DA;margin:2px;padding:.375rem .75rem;">'.PRODUCT_OUT_OF_STOCK.'</span>';
  }
}

 image.gif.09c6257cd77bd16bfe60dc7849fca29e.gifimage.gif.c2da22baa11841d385a4e818e01c2464.gif           
 3. in "\includes\modules\content\index\templates\tpl_cm_i_card_products.php" (around line 31)
 
            replace
            

if ($has_attributes == 0) echo tep_draw_button(IS_PRODUCT_BUTTON_BUY, '', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'products_id', 'sort', 'cPath')) . 'action=buy_now&products_id=' . (int)$card_products['products_id']), NULL, array('params' => 'data-has-attributes="' . $has_attributes . '" data-in-stock="' . (int)$card_products['in_stock'] . '" data-product-id="' . (int)$card_products['products_id'] . '"'), 'btn-light btn-product-listing btn-buy') . PHP_EOL;


            with

if ($has_attributes == 0) {
  if ((int)$card_products['in_stock'] > MAX_OUT_OF_STOCK) {
    echo tep_draw_button(IS_PRODUCT_BUTTON_BUY, '', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'products_id', 'sort', 'cPath')) . 'action=buy_now&products_id=' . (int)$card_products['products_id']), NULL, array('params' => 'data-has-attributes="' . $has_attributes . '" data-in-stock="' . (int)$card_products['in_stock'] . '" data-product-id="' . (int)$card_products['products_id'] . '"'), 'btn-light btn-product-listing btn-buy') . PHP_EOL;
  } else {
    echo '<span style="background:#F8D7DA;margin:2px;padding:.375rem .75rem;">'.PRODUCT_OUT_OF_STOCK.'</span>';
  }
}


 4. in "includes\modules\content\index_nested\templates\tpl_cm_in_card_products.php" (around line 31)
 
            replace
            

if ($has_attributes == 0) echo tep_draw_button(IS_PRODUCT_BUTTON_BUY, '', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'products_id', 'sort', 'cPath')) . 'action=buy_now&products_id=' . (int)$card_products['products_id']), NULL, array('params' => 'data-has-attributes="' . $has_attributes . '" data-in-stock="' . (int)$card_products['in_stock'] . '" data-product-id="' . (int)$card_products['products_id'] . '"'), 'btn-light btn-product-listing btn-buy') . PHP_EOL;

                    
            with

if ($has_attributes == 0) {
  if ((int)$card_products['in_stock'] > MAX_OUT_OF_STOCK) {
    echo tep_draw_button(IS_PRODUCT_BUTTON_BUY, '', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'products_id', 'sort', 'cPath')) . 'action=buy_now&products_id=' . (int)$card_products['products_id']), NULL, array('params' => 'data-has-attributes="' . $has_attributes . '" data-in-stock="' . (int)$card_products['in_stock'] . '" data-product-id="' . (int)$card_products['products_id'] . '"'), 'btn-light btn-product-listing btn-buy') . PHP_EOL;
  } else {
    echo '<span style="background:#F8D7DA;margin:2px;padding:.375rem .75rem;">'.PRODUCT_OUT_OF_STOCK.'</span>';
  }
}

 

The Product Cards will now either display the cart button or an out of stock message.

In addition there is an SQL insert that needs to be run against the database to add the Stock Level that is considered "Out of Stock".
This adds the out of stock option to Configuration>Maximum Vales in administration. I have set the Out of Stock level to 0 and the sort_order to 4.

    insert into configuration ( configuration_title,configuration_key,configuration_value,configuration_description,configuration_group_id,sort_order,date_added ) values ( 'Out of Stock Level','MAX_OUT_OF_STOCK','0','At or Below this number (in stock) means the item is considered Out of Stock',3,4,now() );

To implement the changes

1. Copy on the new php files for the pi system.
2. Make the changes to the four files detailed above.
2. Update the database to add the new row to the configuration table.
3. In administration go into Layout Modules>Product Info & install and configure the two new modules. Disable the Buy Now module.
4. In administration go into Configuration>Maximum Values and set the value that is considered Out of Stock if you wish to use a value other than 0.

Hopefully, that should give you what you want.

 

Note that to change the 'Out of Stock' message you need to update both  "includes\languages\english.php" and also "includes\languages\english\modules\pi\product_info\pi_out_of_stock.php".

If you want you can change the definition in the latter to 

  const PI_OUT_OF_STOCK_WARNING      = PRODUCT_OUT_OF_STOCK;

but that ties the PI module to the english.php update, so I haven't made that change in the file in the zip.

  

There is probably a better way to update the product listing cards without changing the code - I'd be interested to know the details if there is.
 

OutOfStock.zip

Link to comment
Share on other sites

 

I've just noticed there is a Stock option in the Configuration side of things so setting the Out Of stock level should logically be done there.

Functionally it makes no difference, but if you want to make this change you need to :-

 

1. Run the following against the database

update configuration set configuration_key='STOCK_OUT_OF_STOCK',configuration_group_id=9,sort_order=6 where configuration_key='MAX_OUT_OF_STOCK';

2. Update the following five files and change     MAX_OUT_OF_STOCK   to    STOCK_OUT_OF_STOCK

      a) "\templates\default\includes\components\product_listing.php"

      b) "\includes\modules\content\index\templates\tpl_cm_i_card_products.php"

      c) "\includes\modules\content\index_nested\templates\tpl_cm_in_card_products.php"

      d) "\includes\modules\pi\product_info\templates\tpl_pi_add_to_cart_button.php"

      e) "\includes\modules\pi\product_info\templates\tpl_pi_out_of_stock.php"

 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...