Jump to content


  • Posts

  • Joined

  • Last visited

Profile Information

  • Gender
  • Location
    Norfolk, UK

Recent Profile Visitors

6,983 profile views

disco_ii_disco's Achievements


Rookie (2/14)

  • Dedicated Rare
  • First Post
  • Collaborator Rare
  • Conversation Starter Rare
  • Week One Done

Recent Badges



  1. Another great tip. A line of code which I will use a lot, going forward. I inserted the debug code and there is no change in the stock_level at the beginning, middle or end of my code snippet. It is always showing the out of date stock level. Therefore, the problem is before it gets to the code snippet. The below example had been updated, via the API, to show a stock level of 13: [0] At line 3, the stock_status is: True [1] At line 5, the stock_level is: 12 [2] The stock_status is: True [3] The stock_level is: 12 [4] The stock_level_supplier is: 0 [5] The stock_level_shop is: 5 [6] The stock_level_warehouse is: 7 [7] At line 60, the stock_status is: True [8] At line 62, the stock_level is: 12
  2. All SQL queries that contain stock_level information, both in the Cubecart tables and the custom table, are not cached (as confirmed by the debug section). 16. Hack: 1626816962.30120 --- Duration: 264 µs [NOT CACHED] SELECT `stock_level`, `product_code`, `upc`, `jan`, `isbn`, `image` FROM `CubeCart_option_matrix` WHERE CubeCart_option_matrix.product_id = '1008' AND CubeCart_option_matrix.options_identifier IS NULL AND CubeCart_option_matrix.status = '1' ; 21. Hack: 1626816962.30170 --- Duration: 176 µs [NOT CACHED] SELECT `stock_level`, `product_code`, `upc`, `jan`, `isbn`, `image` FROM `CubeCart_option_matrix` WHERE CubeCart_option_matrix.product_id = '1008' AND CubeCart_option_matrix.options_identifier IS NULL AND CubeCart_option_matrix.status = '1' ; 24. Hack: 1626816962.30250 --- Duration: 282 µs [NOT CACHED] SELECT SQL_CALC_FOUND_ROWS MAX(stock_level) AS `stock_level` FROM `CubeCart_option_matrix` WHERE CubeCart_option_matrix.product_id = '1008' AND CubeCart_option_matrix.status = '1' AND CubeCart_option_matrix.use_stock = '1' LIMIT 1; 25. Hack: 1626816962.30280 --- Duration: 206 µs [NOT CACHED] SELECT SQL_CALC_FOUND_ROWS `stock_level` FROM `CubeCart_inventory` WHERE CubeCart_inventory.product_id = '1008' LIMIT 1; 75. Hack: 1626816962.30830 --- Duration: 499 µs [NOT CACHED] SELECT `stock_level` FROM `stock_levels` WHERE stock_levels.product_id = '1008' AND stock_levels.location_id = '1' ORDER BY location_id ; 131. Hack: 1626816962.34640 --- Duration: 567 µs [NOT CACHED] SELECT SQL_CALC_FOUND_ROWS `stock_level` FROM `CubeCart_inventory` WHERE CubeCart_inventory.product_id = '7552' LIMIT 1;
  3. Yes, when "Enabling Caching" is set to "disabled" (in admin) it fixes the problem: The debug information and the stock level information on the page display correctly. Once caching is turned back on, the out of date information is then displayed - until the cache is cleared.
  4. Thank you for the debug code tip - I'll use this a lot going forward. Here is an example output: [0] The stock_status is: True [1] The stock_level is: 17 [2] The stock_level_supplier is: 0 [3] The stock_level_shop is: 17 [4] The stock_level_warehouse is: 0 Then... I made a change to the stock level for this product, in my system; I updated Cubecart via my API; I checked the stock change had been applied in database (it was also showing correctly in Cubecart admin); I reloaded the product page (on two different computers). No change to the stock levels were shown on either computer. The debug information was exactly the same as above (i.e before the change). I cleared the cache and refreshed the page. Stock level change shown.
  5. The problem I am having must be due to this part of the code: $GLOBALS['smarty']->assign('STOCK_STATUS', $stock_status, true); $GLOBALS['smarty']->assign('STOCK_LEVEL', $stock_level, true); $GLOBALS['smarty']->assign('STOCK_LEVEL_SUPPLIER', $stock_level_supplier, true); $GLOBALS['smarty']->assign('STOCK_LEVEL_SHOP', $stock_level_shop, true); $GLOBALS['smarty']->assign('STOCK_LEVEL_WAREHOUSE', $stock_level_warehouse, true); There shouldn't be a situation where where product_id is A and location_id is B. I wrote it like this so you can query by different location ids. (Most of the code was reused from parts of the catalagoue class). $product['available_to_order'] is an integer field I have in my inventory table, that gets updated through my API.
  6. Here is the code snippet: <?php if ((bool)$product['use_stock_level']) { $stock_level_supplier = $product['available_to_order']; $stock_level_warehouse = (int)$GLOBALS['chris']->getProductLocationStockLevel ($product['product_id'], 1); //(int)$stock_level already defined in catalogue.class.php $stock_level_shop = $stock_level - (int)$stock_level_warehouse; //there could be a higher stock level at shop than the actual stock_level (due to stock ready to be transferred for web orders) - so reduce the stock level accordingly... if ($stock_level_shop > $stock_level) $stock_level_shop = $stock_level; //$stock_level already defined in catalogue.class.php if ($stock_level <= 0) { // Out of Stock if (!$GLOBALS['config']->get('config', 'basket_out_of_stock_purchase')) { // Not Allowed $allow_purchase = false; $out = true; } $stock_level_status = ($product['available_to_order']>0 || $stock_level_supplier>0) ? 1 : 0; $in_stock_at_warehouse = 0; $in_stock_at_shop = 0; } else { $stock_level_status = 1; $in_stock_at_warehouse = ($stock_level_warehouse>0) ? 1 : 0; $in_stock_at_shop = ($stock_level_shop>0) ? 1 : 0; } //added true to prevent caching 4/7/21 $GLOBALS['smarty']->assign('STOCK_STATUS', $stock_status, true); $GLOBALS['smarty']->assign('STOCK_LEVEL', $stock_level, true); $GLOBALS['smarty']->assign('STOCK_LEVEL_SUPPLIER', $stock_level_supplier, true); $GLOBALS['smarty']->assign('STOCK_LEVEL_SHOP', $stock_level_shop, true); $GLOBALS['smarty']->assign('STOCK_LEVEL_WAREHOUSE', $stock_level_warehouse, true); $GLOBALS['smarty']->assign('IN_STOCK_AT_WAREHOUSE', $in_stock_at_warehouse, true); $GLOBALS['smarty']->assign('IN_STOCK_AT_SHOP', $in_stock_at_shop, true); } ?> And the function to get the location stock level is just: public function getProductLocationStockLevel ($product_id, $location_id=1) { if (($stock_level_at_location = $GLOBALS['db']->select('stock_levels', array('stock_level'), array('product_id' => (int)$product_id, 'location_id' => $location_id), 'location_id', false, 1, false)) !== false) { $qty_at_location = $stock_level_at_location[0]['stock_level']; } else { $qty_at_location = 0; } return $qty_at_location; }
  7. I am presuming my code snippet, which runs at class.cubecart.display_product, is saving the variables, and not refreshing: $GLOBALS['smarty']->assign('STOCK_LEVEL_SUPPLIER', $stock_level_supplier, true); $GLOBALS['smarty']->assign('STOCK_LEVEL_SHOP', $stock_level_shop, true); $GLOBALS['smarty']->assign('STOCK_LEVEL_WAREHOUSE', $stock_level_warehouse, true); I added the true part recently, as this is supposed to save as a nocache variable: https://www.smarty.net/docs/en/caching.cacheable.tpl
  8. I think if I can just find a way of knowing the name of the cache file, I can delete the file when my API updates the stock.
  9. Same result when manually changing values (in phpMyAdmin) or using my API.
  10. The query is not being cached: Duration: 425 µs [NOT CACHED] SELECT `stock_level` FROM `stock_levels` WHERE stock_levels.product_id = '11262' AND stock_levels.location_id = '1'; The cache/skin file looks fine. It must be the Smarty template variables that are being cached(?) from the code snippet.
  11. Nothing concerning! "Different locations" meant a table I have that stores the stock levels at each physical location: e.g: location_id, product_id, stock_level. The query to get the data, in my code snippet, is the same as the Cubecart getProductStock() code but it looks in my stock_levels table rather than the inventory table. The overall stock level is still stored in the inventory table.
  12. Thank you for your reply bsmither. That has given me a lot more understanding of what is going on. You are right, the text on the product page is coming from a code snippet. The cope snippet: Looks up stock levels in different locations (I have double checked to make sure this query has the cache value set to false) Assigns some smarty variables based on the stock status The text then changes on the product template changes based on the stock status (i.e whether the product is in stock at our shop, our warehouse or only with our suppliers). I am guessing it is the smarty part that is being cached. Is there a way to prevent this, or do you think I'd be better using the unlink method? I have tried assigning the variables as nocache variables and have also tried adding {nocache} {/nocache} to the relevent section of the template. Neither of these solved my problem. https://www.smarty.net/docs/en/caching.cacheable.tpl
  13. Thank you for the reply Noodleman. I have found the code that the admin system uses for clearing the entire cache: if (isset($_GET['clear_cache']) && $_GET['clear_cache'] == 'true') { $GLOBALS['cache']->clear(); $GLOBALS['session']->delete('CLEAR_CACHE'); $GLOBALS['main']->successMessage($GLOBALS['language']->maintain['notify_cache_cleared'], false); httpredir(currentPage(array('clear_cache'))); } Is it possible to clear the cache for a single product? I am guessing not - otherwise this would happen after updating a product in admin.
  14. I have built an API for my CubeCart store to update the stock levels from my till and stock management system. It is working well. However, sometimes old stock levels are being displayed on product pages. I have to keep going in to clear the cache from the Cubecart admin to fix it. Does anyone know a way around this? Is there a way to clear the cache for an individual product? (I am not completely sure how the cache works!) If so, I could do this in the API.
  15. Hi Josh, I was fortunate enough to launch my website 15 years ago - when things were so much easier. It was so easy to launch a website and appear on the first page of Google or Yahoo back then! Nowdays you will have to pay for advertising. Google Shopping is brilliant though. Do you sell items that have a barcode, brand and part number? If so, you can advertise them on there for pennies per click. You can also do targeted adverising on Facebook (for pennies) - not that I have been completely successful with that though. For small businesses, you have to think outside of the box. Be a specialist in your area. Write blog articles, contribute to forums. Do the things that big businesses can not do. Explain more about the products than any big e-commerce site could do. Film explanatory videos for your products - and upload them to YouTube. Answer the questions that people are searching for the answer to. Write lots of good content. All the best, Chris
  • Create New...