Dirty Butter Posted April 30, 2016 Share Posted April 30, 2016 I do a lot of cloning of products, and I sometimes forget to change the stock level to match the variation I'm creating, which is not good. Is there a way to change the core code so it does NOT clone that quantity? Quote Link to comment Share on other sites More sharing options...
bsmither Posted April 30, 2016 Share Posted April 30, 2016 (edited) Two parts: adding a setting in Store Settings, Extra, and adding test for that setting. In the admin skin template settings.index.php: Find: <div><label for="product_clone_images">{$LANG.settings.product_clone_images}</label><span><input name="config[product_clone_images]" id="product_clone_images" type="hidden" class="toggle" value="{$CONFIG.product_clone_images}"></span></div> <div><label for="product_clone_options">{$LANG.settings.product_clone_options}</label><span><input name="config[product_clone_options]" id="product_clone_options" type="hidden" class="toggle" value="{$CONFIG.product_clone_options}"></span></div> <div><label for="product_clone_options_matrix">{$LANG.settings.product_clone_options_matrix}</label><span><input name="config[product_clone_options_matrix]" id="product_clone_options_matrix" type="hidden" class="toggle" value="{$CONFIG.product_clone_options_matrix}"></span></div> <div><label for="product_clone_acats">{$LANG.settings.product_clone_acats}</label><span><input name="config[product_clone_acats]" id="product_clone_acats" type="hidden" class="toggle" value="{$CONFIG.product_clone_acats}"></span></div> Add after: <div><label for="product_clone_main_stock">Main stock level</label><span><input name="config[product_clone_main_stock]" id="product_clone_main_stock" type="hidden" class="toggle" value="{$CONFIG.product_clone_main_stock}"></span></div> You can add a phrase to the language pack if you want. Then, in /admin/sources/products.index.inc.php: Find: $record = $original_product_data[0]; // Add cloned product $date_added = date('Y-m-d H:i:s', time()); $record['date_added'] = $date_added; $record['updated'] = $date_added; if ($GLOBALS['config']->get('config', 'product_clone_code') == 1) $record['product_code'] = generate_product_code($record['name']); Add after: if ($GLOBALS['config']->get('config', 'product_clone_main_stock') != 1) unset($record['stock_level']); Edited May 1, 2016 by bsmither Fixed added PHP statement Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 1, 2016 Author Share Posted May 1, 2016 It's not working for me, and I've tried it several times - with and then without my usual comments before and after changes. $record = $original_product_data[0]; // Add cloned product $date_added = date('Y-m-d H:i:s', time()); $record['date_added'] = $date_added; $record['updated'] = $date_added; if ($GLOBALS['config']->get('config', 'product_clone_code') == 1) $record['product_code'] = generate_product_code($record['name']); if ($GLOBALS['config']->get('config', 'product_clone_main_stock') != 1) unset($record['stock_level']; unset($record['product_id'], $record['popularity']); AND <div><label for="product_clone_images">{$LANG.settings.product_clone_images}</label><span><input name="config[product_clone_images]" id="product_clone_images" type="hidden" class="toggle" value="{$CONFIG.product_clone_images}"></span></div> <div><label for="product_clone_options">{$LANG.settings.product_clone_options}</label><span><input name="config[product_clone_options]" id="product_clone_options" type="hidden" class="toggle" value="{$CONFIG.product_clone_options}"></span></div> <div><label for="product_clone_options_matrix">{$LANG.settings.product_clone_options_matrix}</label><span><input name="config[product_clone_options_matrix]" id="product_clone_options_matrix" type="hidden" class="toggle" value="{$CONFIG.product_clone_options_matrix}"></span></div> <div><label for="product_clone_acats">{$LANG.settings.product_clone_acats}</label><span><input name="config[product_clone_acats]" id="product_clone_acats" type="hidden" class="toggle" value="{$CONFIG.product_clone_acats}"></span></div> <div><label for="product_clone_code">{$LANG.settings.product_clone_code}</label><span><select name="config[product_clone_code]" id="product_clone_code" class="textbox"> <div><label for="product_clone_main_stock">Main stock level</label><span><input name="config[product_clone_main_stock]" id="product_clone_main_stock" type="hidden" class="toggle" value="{$CONFIG.product_clone_main_stock}"></span></div> {foreach from=$OPT_PRODUCT_CLONE_CODE item=option}<option value="{$option.value}"{$option.selected}>{$option.title}</option>{/foreach} I do NOT use the Option Matrix - would that make a difference? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 1, 2016 Share Posted May 1, 2016 Double check the HTML: 1: <div><label for="product_clone_options_matrix">{$LANG.settings.product_clone_options_matrix}</label><span><input name="config[product_clone_options_matrix]" id="product_clone_options_matrix" type="hidden" class="toggle" value="{$CONFIG.product_clone_options_matrix}"></span></div> 2: <div><label for="product_clone_acats">{$LANG.settings.product_clone_acats}</label><span><input name="config[product_clone_acats]" id="product_clone_acats" type="hidden" class="toggle" value="{$CONFIG.product_clone_acats}"></span></div> 3: <div><label for="product_clone_code">{$LANG.settings.product_clone_code}</label><span><select name="config[product_clone_code]" id="product_clone_code" class="textbox"> 4: <div><label for="product_clone_main_stock">Main stock level</label><span><input name="config[product_clone_main_stock]" id="product_clone_main_stock" type="hidden" class="toggle" value="{$CONFIG.product_clone_main_stock}"></span></div> Move line 4 between lines 2 and 3. And how is it not working? Do you see or not see the choice in the admin screen? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 1, 2016 Author Share Posted May 1, 2016 Sorry - had to write my last comment twice and left out that it was crashing php - white screen on saving the source file. But moving the template line did not fix it - still crashes. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 1, 2016 Share Posted May 1, 2016 It is this: unset($record['stock_level']; A missing close parenthesis. My bad. unset($record['stock_level']); I have fixed it above. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 1, 2016 Author Share Posted May 1, 2016 THANK YOU AS ALWAYS!! Would it make sense to suggest this in GitHub as a core change? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 2, 2016 Share Posted May 2, 2016 I agree that stock level is not an inherent characteristic of a cloned product. I believe its translated description(s), image(s), options, options matrix, and categories are inherent characteristics of a cloned product. These are specific inherent characteristics that can be switched off for the cloning process. Other non-inherent characteristics are: date added, date updated, product code, product id, and popularity. These are not copied in the cloning process. So, yes, I believe main stock levels (and, perhaps, matrix stock levels, but keep the matrix) should not be copied in the cloning process. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 2, 2016 Author Share Posted May 2, 2016 https://github.com/cubecart/v6/issues/1091 Quote Link to comment Share on other sites More sharing options...
Al Brookbanks Posted May 11, 2016 Share Posted May 11, 2016 Thanks guys... rolled out for 6.0.12. 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.