Claudia Posted September 12, 2022 Share Posted September 12, 2022 I just noticed that when someone purchases and item with paypal it does not update the stock level on the store front until I go into admin and clear the cache. It does update it in admin, just not in the store front. What to do? Thanks Running CC 6.4.7 Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 12, 2022 Share Posted September 12, 2022 While in admin, CubeCart does not use the cache. So, every detail is 'fresh'. Since the inventory stock level is correct (results of a fresh query), we must look at the storefront code to see if the stock level detail is coming from a fresh query or from the cache. There is a function in the catalogue.class.php file, getProductStock(). Here, there are two database queries: Somewhere in line 1394: $GLOBALS['db']->select('CubeCart_option_matrix', $rows, $where, false, 1, false, false) Somewhere in line 1405: $GLOBALS['db']->select('CubeCart_inventory', array('stock_level'), array('product_id' => (int)$product_id), false, 1, false, false) The last false of these statements tells the select() function to not use the cache -- always get results from a fresh database query. So, where is the stale stock level appearing on your site? Could this be a detail provided by a plugin or code snippet? Quote Link to comment Share on other sites More sharing options...
Claudia Posted September 12, 2022 Author Share Posted September 12, 2022 This is the only code change in that file - Line 755 // START My do not show product on Cat Page if Sold $where = " AND INV.available = '1'"; $where2 = $this->outOfStockWhere(false, 'INV', true); if (($result = $GLOBALS['db']->query('SELECT I.product_id FROM `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_category_index` as I, `'.$GLOBALS['config']->get('config', 'dbprefix').'CubeCart_inventory` as INV WHERE I.cat_id = '.$category_id.' AND I.product_id = INV.product_id AND INV.status = 1'.$where.$where2)) !== false) { // END My do not show product on Cat Page if Sold Make sure this is on its own line $this->_category_count = $GLOBALS['db']->numrows(); if (isset($_GET['sort']) && is_array($_GET['sort'])) { foreach ($_GET['sort'] as $field => $direction) { $order[$field] = (strtolower($direction) == 'asc') ? 'ASC' : 'DESC'; break; } This is my code starting at Line 1385. Stock CC6.4.7 public function getProductStock($product_id = null, $options_identifier_string = null, $return_max = false, $check_existing = false, $quantity = false) { // Choose option combination specific stock if (is_numeric($product_id) && (!empty($options_identifier_string) || $return_max == true)) { if ($return_max) { $rows = 'MAX(stock_level) AS `stock_level`'; $where = array('product_id' => (int)$product_id, 'status' => 1, 'use_stock' => 1); } else { $rows = array('stock_level', 'restock_note'); $where = array('product_id' => (int)$product_id, 'options_identifier' => $options_identifier_string, 'status' => 1, 'use_stock' => 1); } if($products_matrix = $GLOBALS['db']->select('CubeCart_option_matrix', $rows, $where, false, 1, false, false)) { if (is_numeric($products_matrix[0]['stock_level'])) { if (!empty($products_matrix[0]['restock_note'])) { $GLOBALS['session']->set('restock_note', $products_matrix[0]['restock_note']); } return $products_matrix[0]['stock_level']; } } } // Fall back to traditional stock check if there are no results for the combination or it is not used if (is_numeric($product_id) && ($products = $GLOBALS['db']->select('CubeCart_inventory', array('stock_level'), array('product_id' => (int)$product_id), false, 1, false, false)) !== false) { // Check this product id isn't already in the cart with different options identifier if ($check_existing) { if (is_array($check_existing)) { foreach ($check_existing as $key => $value) { if ($value['id'] == $product_id) { $products[0]['stock_level'] -= $quantity; } } } } return $products[0]['stock_level']; } return false; } Quote Link to comment Share on other sites More sharing options...
bsmither Posted September 12, 2022 Share Posted September 12, 2022 So, where is the stale stock level appearing on your site? Could this be a detail provided by a plugin or code snippet? Could the observed product, where the stock level seems to be stale, have options that are managed in the Options Matrix Table? If so, then the code that calls getProductStock() could be passing a parameter that says '$return_max = true'. If this is happening, then the stock level of the specific option combination that has the greatest stock level is what is going to be displayed. Please also let us know what the setting is for admin, Store Settings, Stock tab, "Main stock level as matrix stock level summary". Quote Link to comment Share on other sites More sharing options...
Claudia Posted September 12, 2022 Author Share Posted September 12, 2022 "Main stock level as matrix stock level summary". unchecked I don't use options Not sure what you mean by stale stock level. Here is my code for the content.product in my skin FYI: I have all my product code in this file. I don't use call to action, horizonal, vertical {if ($CTRL_ALLOW_PURCHASE) && (!$CATALOGUE_MODE)} <div class="row collapse"> {if $PRODUCT.available <= 0} <div class="small-12 columns"> <div class="font13"> </div> </div> {else} <div class="prodprice" style="border-top:1px dotted #C0C0C0;"> {if $PRODUCT.ctrl_sale} <span class="old_price" id="fbp"{if !$CTRL_HIDE_PRICES} data-price="{$PRODUCT.full_base_price}"{/if}>{$PRODUCT.price}</span> <span class="sale_price" id="ptp"{if !$CTRL_HIDE_PRICES} data-price="{$PRODUCT.price_to_pay}"{/if}>{$PRODUCT.sale_price}</span> {else} <span class="ptp" {if !$CTRL_HIDE_PRICES} data-price="{$PRODUCT.price_to_pay}"{/if}>{$PRODUCT.price}</span> {/if} </div> <div class="row collapse"> <div class="small-2 medium-3 columns"> <input type="text" name="quantity" value="1" maxlength="3" class="quantity required text-center" > <input type="hidden" name="add" value="{$PRODUCT.product_id}"> </div> <div class="small-10 medium-9 columns"> <link itemprop="availability" href="http://schema.org/InStock" /> <button type="submit" value="Add to Basket" class="nopad button greenb postfix expand ">Add to Basket</button> </div> {/if} </div></div> {else} {if $CTRL_HIDE_PRICES} <p class="buy_button"><strong>{$LANG.catalogue.login_to_view}</strong></p> {else if $CTRL_OUT_OF_STOCK} <link itemprop="availability" href="http://schema.org/OutOfStock" /> <div class="font13 pad-top ">Not available for purchase thru this store </div> {/if} {/if} </div> {if $PRODUCT.stock_level} <div class="row collapse"> <div class="small-12 medium-11 large-11 columns"> <div class="font14 bold pad-top ">{$PRODUCT.stock_level} Available thru this Store</div> </div> <div class="row collapse"> <div class="small-12 medium-12 large-12 columns"> <div class="font12">Place quantity to purchase in the box - up to the available limit</div> </div> </div> </div> {/if} Quote Link to comment Share on other sites More sharing options...
Claudia Posted September 14, 2022 Author Share Posted September 14, 2022 I have tried stock code, I have changed my code around and this still happens. Only on the product page. The category page does not show the buy button - it shows my availability button. But on the product page the quantity does not change until I clear the cache in admin. Is this the way it's always been and I'm just now noticing it? If so, what happens if someone buys something and I'm not around to clear the cache. Can they buy over the inventory I have. I've probably done something stupid that I haven't found yet. I just don't know. No code snippets or plugins I use could cause this. I use AIOS, PayPal, Store Health Check (Daren) and a couple of snippets Brian made for me. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.