zipurman Posted July 4, 2020 Share Posted July 4, 2020 Not sure if this will help anyone, as I am new to Phoenix and OSCommerce. I wanted to add product inventory counts and hide the add to cart button if zero. I couldnt find a solution after an hour of looking, so I write the following which works as needed. Hope this helps someone. Edit the file: includes/functions/html_output.php find the function "tep_draw_button" and go to the bottom of the function. right before "return $button;" add the following: $checkparams = explode( ' ', $params['params'] ); $newparams = array(); foreach ( $checkparams as $item ) { $newtest = explode( '=', $item ); $newparams[] = $newtest; } $finalparams = array(); foreach ( $newparams as $item ) { $item[0] = str_replace( '"', '', $item[0] ); $item[1] = str_replace( '"', '', $item[1] ); $finalparams["{$item[0]}"] = $item[1]; } if ( isset( $finalparams['data-in-stock'] ) ) { if ( empty( $finalparams['data-in-stock'] ) ) { $button = '<div style="color: red; display: inline-block; padding: 5px;">SOLD OUT</div>'; } else { $button .= '<br/>' . $finalparams['data-in-stock'] . ' In Stock'; } } Link to comment Share on other sites More sharing options...
zipurman Posted July 4, 2020 Author Share Posted July 4, 2020 Sorry, here is a new version as some quantities are less than zero and this will catch them too. $checkparams = explode( ' ', $params['params'] ); $newparams = array(); foreach ( $checkparams as $item ) { $newtest = explode( '=', $item ); $newparams[] = $newtest; } $finalparams = array(); foreach ( $newparams as $item ) { $item[0] = str_replace( '"', '', $item[0] ); $item[1] = str_replace( '"', '', $item[1] ); $finalparams["{$item[0]}"] = $item[1]; } if ( isset( $finalparams['data-in-stock'] ) ) { if ( (int) $finalparams['data-in-stock'] <=0 ) { $button = '<div style="color: red; display: inline-block; padding: 5px;">SOLD OUT</div>'; } else { $button .= '<br/>' . $finalparams['data-in-stock'] . ' In Stock'; } } Link to comment Share on other sites More sharing options...
♥14steve14 Posted July 4, 2020 Share Posted July 4, 2020 Is there a way of making this so no core files are touched or modified. Oscommerce has come along way and in most cases code changes like this are not required. Then may be upload it as an addon in the correct place so others can find and use it. REMEMBER BACKUP, BACKUP AND BACKUP Link to comment Share on other sites More sharing options...
Heatherbell Posted July 4, 2020 Share Posted July 4, 2020 2 hours ago, zipurman said: Not sure if this will help anyone, as I am new to Phoenix and OSCommerce. I wanted to add product inventory counts and hide the add to cart button if zero. The Phoenix Club is the specific forum for CE Phoenix - post your ideas and suggestions there to receive help direct from the lead developers Link to comment Share on other sites More sharing options...
zipurman Posted July 4, 2020 Author Share Posted July 4, 2020 I'll see what I can come up with for a plugin that doesnt touch core files Link to comment Share on other sites More sharing options...
zipurman Posted July 4, 2020 Author Share Posted July 4, 2020 BTW, It would be an easy add to the core and I am sure most shop owners would appreciate the "OPTION" of showing this information. Link to comment Share on other sites More sharing options...
zipurman Posted July 4, 2020 Author Share Posted July 4, 2020 Okay, I created the following hook instead. Not sure if this will work in oscommerce as I only tested in Phoenix. Just thought I would share here in case it's helpful. create a file /includes/hooks/shop/zipurInStock/pi_hooks.php <?php /* * zipurInStock - Version 0.1.0 - July 4, 2020 * Code provided by zipur of zipur.ca * Use as you like ;) */ class hook_shop_zipurInStock_pi_hooks { function listen_showInStock() { if ( $this->show_areas() == 1 || $this->show_areas() == 2 ) { ?> <script> $(function () { $(".btn-buy").each(function() { var qty = $( this ).attr( "data-in-stock" ); if (typeof qty === 'undefined') qty = 0; if (qty > 0){ var extraclass = ''; if (qty < 2){ extraclass = 'zipreallylowstock'; } else if (qty < 6){ extraclass = 'ziplowstock'; } $(this).after('<div class="zipinstock"><span class="zipqty ' + extraclass + '">' + qty + '</span> In Stock</div>'); } else { $(this).after('<div class="zipsoldout">SOLD OUT</div>'); $(this).remove(); } }); }); </script> <?php } } function show_areas() { global $PHP_SELF; if ( basename( $PHP_SELF ) == 'product_info.php' ) { return 1; } else if ( basename( $PHP_SELF ) == 'index.php' ) { return 2; } else { return 0; } } } Then add the following 2 lines near the end of the file /templates/default/includes/components/template_bottom.php $OSCOM_Hooks->register( 'zipurInStock' ); $OSCOM_Hooks->call( 'zipurInStock', 'showInStock' ); Then you can style as needed in user.css or stylesheet.css .zipsoldout { color: red; display: inline-block; padding: 5px; } .zipinstock{ padding: 10px; text-align: center; } .zipqty{ color: #333; } .zipreallylowstock{ color: #bd4205; } .ziplowstock{ color: #f28b06; } Seems to work good so far Link to comment Share on other sites More sharing options...
♥raiwa Posted July 4, 2020 Share Posted July 4, 2020 You do not need to add hook register and call. Use the available preplaced siteWide hooks. you can use existing native bootstrap css classes for styling. No need for custom css. if I well remember, something like this is already available as a Phoenix supporter code you should add multi language support About Me: http://www.oscommerce.com/forums/user/249059-raiwa/ Need help? How To Get The Help You Need Is your version of osC up to date? You'll find the latest osC community version CE Phoenix here. Public Phoenix Change Log Cheat Set on Google Sheets Link to comment Share on other sites More sharing options...
zipurman Posted July 4, 2020 Author Share Posted July 4, 2020 2 hours ago, raiwa said: You do not need to add hook register and call. Use the available preplaced siteWide hooks. you can use existing native bootstrap css classes for styling. No need for custom css. if I well remember, something like this is already available as a Phoenix supporter code you should add multi language support I wasnt able to find any docs on existing hooks that would allow me hook into the product_info and index pages as required. Would love to see an example or a link to an example of the right way to do that. The css is specific to the code. I realize I could leverage existing css classes, but this isnt a full and complete hook ... just a shared example of something I was playing with. A full hook that is published to the library should have much more work to it of course. Link to comment Share on other sites More sharing options...
zipurman Posted July 5, 2020 Author Share Posted July 5, 2020 9 hours ago, raiwa said: You do not need to add hook register and call. Use the available preplaced siteWide hooks. you can use existing native bootstrap css classes for styling. No need for custom css. if I well remember, something like this is already available as a Phoenix supporter code you should add multi language support Thanks raiwa, your comment lead me to a better way of doing it. Create a file /includes/hooks/shop/siteWide/zipurInStock.php <?php /* * zipurInStock - Version 0.1.1 - July 4, 2020 * Code provided by zipur of zipur.ca * Use as you like ;) */ class hook_shop_siteWide_zipurInStock { var $version = '0.1.1'; function listen_injectBodyEnd() { if ( $this->show_areas() == 1 || $this->show_areas() == 2 ) { ?> <script> $(function () { $(".btn-buy").each(function() { var qty = $( this ).attr( "data-in-stock" ); if (typeof qty === 'undefined') qty = 0; if (qty > 0){ var extraclass = ''; if (qty < 2){ extraclass = 'zipreallylowstock'; } else if (qty < 6){ extraclass = 'ziplowstock'; } $(this).after('<div class="zipinstock"><span class="zipqty ' + extraclass + '">' + qty + '</span> In Stock</div>'); } else { $(this).after('<div class="zipsoldout">SOLD OUT</div>'); $(this).remove(); } }); }); </script> <?php } } function show_areas() { global $PHP_SELF; if ( basename( $PHP_SELF ) == 'product_info.php' ) { return 1; } else if ( basename( $PHP_SELF ) == 'index.php' ) { return 2; } else { return 0; } } } I would use the boostrap css, but this gives more control as bootstrap has limited colors as far as I can see. This css can be added to user.css or stylesheet.css .zipsoldout { color: red; display: inline-block; padding: 5px; } .zipinstock{ padding: 10px; text-align: center; } .zipqty{ color: #4d763b; } .zipreallylowstock{ color: #bd4205; } .ziplowstock{ color: #f28b06; } Link to comment Share on other sites More sharing options...
♥raiwa Posted July 5, 2020 Share Posted July 5, 2020 user.css may be removed in future versions bootstrap has native helper classes for padding and margin, not only colors explore the bootstrap documentation explore core modules how things are made there using bootstrap css classes, if someone customizes his bootstrap theme, the styles will adjust accordingly without additional modifications have a look in: templates/default/includes/hooks/shop/siteWide/ to see other hooks and how page selection and language file inclusion can be easy done your hook should also be placed there buy buttons are also used in other pages: specials.php, products_new.php using a header tag module instead of hook would allow to inject the script into the footer_scripts area and add configuration entries to easy adjust things in admin. explore the existing header tag modules to see how this is made About Me: http://www.oscommerce.com/forums/user/249059-raiwa/ Need help? How To Get The Help You Need Is your version of osC up to date? You'll find the latest osC community version CE Phoenix here. Public Phoenix Change Log Cheat Set on Google Sheets Link to comment Share on other sites More sharing options...
zipurman Posted July 5, 2020 Author Share Posted July 5, 2020 Thanks raiwa, I was just looking at your KissIT Image Thumbnailer Pro project I'll review your comments and see what I can come up with. Just learning osCommerce and Phoenix. A week ago I hadnt even heard of either project I am working on this for a friend that had a 12 year old store running 2.2. I have since migrated all to Phoenix and its going good. As a result, I took interest in the osCommerce and Phoenix projects and have just been playing around. Thanks again for your time to point me in the right direction! Zip Link to comment Share on other sites More sharing options...
♥peterpil19 Posted July 6, 2020 Share Posted July 6, 2020 22 hours ago, zipurman said: Thanks raiwa, I was just looking at your KissIT Image Thumbnailer Pro project I'll review your comments and see what I can come up with. Just learning osCommerce and Phoenix. A week ago I hadnt even heard of either project I am working on this for a friend that had a 12 year old store running 2.2. I have since migrated all to Phoenix and its going good. As a result, I took interest in the osCommerce and Phoenix projects and have just been playing around. Thanks again for your time to point me in the right direction! Zip Hi Zip, If you have an ongoing interest in Phoenix, I recommend you join us in the Phoenix Club. Unlike old osCommerce, the approach now is to avoid editing core code which makes it easier for shopowners to apply updates. Where there is no away around a core code change, then let the core team know in case they can address it in a future core code release e.g. by adding a pre-placed hook. Peter CE PHOENIX SUPPORTER Support the Project, go PRO and get access to certified add ons Full-time I am a C-suite executive of a large retail company in Australia. In my spare time, I enjoying learning about web-design. Download the latest version of CE Phoenix from gitHub here Link to comment Share on other sites More sharing options...
zipurman Posted July 6, 2020 Author Share Posted July 6, 2020 1 minute ago, peterpil19 said: Hi Zip, If you have an ongoing interest in Phoenix, I recommend you join us in the Phoenix Club. Unlike old osCommerce, the approach now is to avoid editing core code which makes it easier for shopowners to apply updates. Where there is no away around a core code change, then let the core team know in case they can address it in a future core code release e.g. by adding a pre-placed hook. Peter Thanks peterpil19 I have already joined the group and looking to get more involved. Link to comment Share on other sites More sharing options...
sakher1989 Posted July 23, 2020 Share Posted July 23, 2020 I'll see what I can come up with for a plugin that doesnt touch core files Link to comment Share on other sites More sharing options...
zipurman Posted July 23, 2020 Author Share Posted July 23, 2020 2 minutes ago, sakher1989 said: I'll see what I can come up with for a plugin that doesnt touch core files Have a look at this as I did code this to avoid changing any core files. http://zipur.ca/knowledgebase/phoenix-zipurinstock/ Link to comment Share on other sites More sharing options...
zipurman Posted July 24, 2020 Author Share Posted July 24, 2020 This now has several new features, including toggle product layouts to list, 2, 4, 6 grids. http://zipur.ca/knowledgebase/phoenix-zipurinstock/ Zip Link to comment Share on other sites More sharing options...
zipurman Posted October 13, 2020 Author Share Posted October 13, 2020 This hook got absorbed into https://phoenixaddons.com/product/zipur-product-manager/ Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.