Dirty Butter Posted June 13, 2018 Share Posted June 13, 2018 How would I change the stock code on 6.2.1 so the first choice on a Product Listing is inch instead of centimeter? None of our products will ever be metric. Link to comment Share on other sites More sharing options...
bsmither Posted June 13, 2018 Share Posted June 13, 2018 Try this. In administration /sources/products.index.inc.php Near line 837 (CC621), find: $result[0] = array( 'featured' => 1, 'latest' => 1, 'tax_inclusive' => 0, 'use_stock_level' => 1, ); Change to: $result[0] = array( 'featured' => 1, 'latest' => 1, 'tax_inclusive' => 0, 'use_stock_level' => 1, 'dimension_unit' => ($GLOBALS['config']->has('config', 'product_weight_unit') && $GLOBALS['config']->get('config', 'product_weight_unit') == "Lb") ? 'in' : 'cm' , ); The new code is added to an existing line to keep the line numbering the same for the future. In Store Settings, one may choose a weight unit: Lb or Kg. If that unit of measure has been chosen to be Lb, then we will assume, when adding a new product to the inventory, the product dimension unit will be in Inches. Otherwise, in Centimeters. Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 13, 2018 Author Share Posted June 13, 2018 This code works perfectly for 6.2.1 adding a new product THANK YOU! Old products will need a query to change from centimeters to inches I guess. Link to comment Share on other sites More sharing options...
bsmither Posted June 13, 2018 Share Posted June 13, 2018 Well, the SQL query that updated the CubeCart_inventory table to have the 'dimension_unit' column specified a default value of NULL. So, I assume that until any existing product gets edited, this column is empty. As such, we can add a statement to the common area of the Add/Edit Product form. Undo what was done earlier. Near line 1059, find: // Set status to 1 if not set $result[0]['status'] = !isset($result[0]['status']) ? 1 : $result[0]['status']; $result[0]['auto_code_checked'] = (empty($result[0]['product_code'])) ? 'checked="checked"' : ''; $result[0]['seo_path'] = isset($result[0]['product_id']) ? $GLOBALS['seo']->getdbPath('prod', $result[0]['product_id']) : ''; On the blank line following, add: $result[0]['dimension_unit'] = (!isset($result[0]['dimension_unit']) && $GLOBALS['config']->has('config', 'product_weight_unit') && $GLOBALS['config']->get('config', 'product_weight_unit') == "Lb") ? 'in' : (isset($result[0]['dimension_unit']) ? $result[0]['dimension_unit'] :'cm') ; This says that if a 'dimension_unit' doesn't exist, and there is a weight measure of Lb, then use "in". Otherwise, if the 'dimension_unit' does exist, then use it. Otherwise use "cm". Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 13, 2018 Author Share Posted June 13, 2018 Do I have your code done correctly in the right place? // Set status to 1 if not set $result[0]['status'] = !isset($result[0]['status']) ? 1 : $result[0]['status']; $result[0]['auto_code_checked'] = (empty($result[0]['product_code'])) ? 'checked="checked"' : ''; $result[0]['seo_path'] = isset($result[0]['product_id']) ? $GLOBALS['seo']->getdbPath('prod', $result[0]['product_id']) : ''; /* BSMITHER LINE BELOW - USE INCHES NOT CENTIMETERS AS DEFAULT 'use_stock_level' => 1, */ $result[0]['dimension_unit'] = (!isset($result[0]['dimension_unit']) && $GLOBALS['config']->has('config', 'product_weight_unit') && $GLOBALS['config']->get('config', 'product_weight_unit') == "Lb") ? 'in' : (isset($result[0]['dimension_unit']) ? $result[0]['dimension_unit'] :'cm') ; $master_image = isset($_GET['product_id']) ? $GLOBALS['gui']->getProductImage((int)$_GET['product_id']) : ''; $result[0]['master_image'] = !empty($master_image) ? $master_image : 'images/general/px.gif'; If so, it did not work. This test site has almost all my plugins. I'll try it again on one that doesn't. No, still did not work. This sounded like this would be so easy, just like swapping Old above New in Product Condition. But obviously not. Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 13, 2018 Author Share Posted June 13, 2018 Speaking of NULL - could that be set to use inches as the default? Link to comment Share on other sites More sharing options...
bsmither Posted June 13, 2018 Share Posted June 13, 2018 Sure. The value would be in. Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 13, 2018 Author Share Posted June 13, 2018 Attempted to make the NULL to in change in the database while using the original product. index.inc.php code - but it did not have any effect on the already existing products. Your code would be very helpful for a store with few previous products to edit. But with 4k plus, I'll have to work out a query to change the old. I can THEN use your code from now on, and it will be very helpful. I'm still not ready to make the upgrade for our active store, as some key plugins need updating first. So if another approach comes to mind I'll be glad to try it out. Thank you! Link to comment Share on other sites More sharing options...
bsmither Posted June 13, 2018 Share Posted June 13, 2018 Should have. Look at the code in the template products.index.php near line 175. If the dimension_unit is 'in', then this option in the drop down selector gets "selected" (shows as the selected choice). So, either your update to the database didn't happen, or what you did was to change the schema so that new products will default to 'in' if not otherwise set -- which it will be, because the form defaults to the first option, when you press Save. To have the storefront skin show 'in' if otherwise empty and be using Lb as weight - where existing products would not have a value for 'dimension_unit' - we would need to tweak the Catalogue->getProductData() code. Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 14, 2018 Author Share Posted June 14, 2018 I don't know what I did wrong. I'll work on it again tomorrow when I'm fresh. I did play around with the database on a test site that has all my products in it. It appears I was worried unnecessarily about the old products having cm dimensions. An old product does not get a dimension set until it is edited. Before that, the old products have an empty value for dimension. If that's so, your code will be all I need,. If I'm right about that, that would explain why it didn't effect existing products. Like I said, I'll look at it all again tomorrow. Link to comment Share on other sites More sharing options...
Dirty Butter Posted June 14, 2018 Author Share Posted June 14, 2018 Alright, I've spent time on it today. First of all, prior existing products that have not been opened in 6.2.1 have NULL in the dimension_unit column. They will remain blank dimensions on the storefront, but empty dimensions do not show because of the {if} statement on the content.product.php file. As soon as you save an old product in Admin you have to set the dimension to inches or it will save as the centimeter that shows. But again, if dimensions have not been added, it won't matter. BUT now that I understand that nothing will change to cm unless I edit it, I now realize I'm fretting over a non-issue. If I have a reason to edit an old product I will try to get in the habit of changing the cm to in. Since nothing shows on the front unless there are numbers in the width, height, length - it doesn't really matter. And I surely won't be going back through 3k+ in stock items to take them individually out of storage, measure them, change the listing in Admin, and then put them back in storage. As I create new products I will start changing to inches and MAY add dimension. I haven't decided about that yet. It might invite lots of customer questions if they see that new ones have dimensions, but most of the older ones do not. Thank you for your efforts, Bsmither. I had wrongly assumed all the old ones would suddenly show cm on the storefront. I now realize they will not until I need them to show, and I can then choose inches. I apologize as once again I have wasted your valuable time. Link to comment Share on other sites More sharing options...
bsandall Posted July 10, 2018 Share Posted July 10, 2018 I ran a simple SQL query to update all my existing product listings to default to inches: UPDATE `CubeCart_inventory` SET `dimension_unit`='in'; They still will not display any product dimensions until you specify width/depth/height, but at least you won't have to select 'inches' every time when you do. Link to comment Share on other sites More sharing options...
Dirty Butter Posted July 10, 2018 Author Share Posted July 10, 2018 Thanks for that, @bsandall . A simple enough query to eliminate having to learn a new step in listing/editing. Link to comment Share on other sites More sharing options...
bsandall Posted July 11, 2018 Share Posted July 11, 2018 On 7/10/2018 at 12:42 PM, Dirty Butter said: Thanks for that, @bsandall . A simple enough query to eliminate having to learn a new step in listing/editing. The above would only apply to existing items; you'd have to do some of the edits bsmither mentioned and/or change the database column default value to 'in' instead of null in order to have new items default to inches as well. Link to comment Share on other sites More sharing options...
Dirty Butter Posted July 12, 2018 Author Share Posted July 12, 2018 Thanks for the reminder - this whole thread had been pushed to the back of my thinking while I was making the 6.2+upgrade on our main store. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.