Tim Homola Posted July 1, 2022 Share Posted July 1, 2022 When I duplicate a product, I can change the reference on the basic settings tab in the back office, but the front end it still shows the original reference. This is causing a big problem with my order importing program that gets the wrong products assignet to quickbooks. How can I change the reference? I have cleared the cache, reindexed, etc. Link to comment Share on other sites More sharing options...
Prestachamps Posted July 1, 2022 Share Posted July 1, 2022 Hi, it is a product with combinations? If you want and will help you I have a custom modification to empty the product and combination references at product duplication. Have a nice day, Leo. 1 Link to comment Share on other sites More sharing options...
Tim Homola Posted July 1, 2022 Author Share Posted July 1, 2022 Thank you for your response Leo! Yes, it does have combinations but I want the same combinations and don't want to enter them again, thus trying to duplicate. I want everything to be the same except for the name, picture, reference, and desctiption. I'm copying the same toy car, just with a different livery (paint job). Link to comment Share on other sites More sharing options...
Tim Homola Posted July 5, 2022 Author Share Posted July 5, 2022 I have researched the problem clearer. It appears you cannot properly duplicate a product that has combinations. This keeps the same regference as the original part duplicated, even though it shows in the backend as what you edit it to. When you place an order with it, the original reference appears. Pretty sure this is a PS bug. Duplicating other products works fine and you can duplicate and edit the reference properly. What can I do? I have a large number of parts I want to duplicate and don't want to manually have to go in and build all the combinations from scratch? Link to comment Share on other sites More sharing options...
knacky Posted July 6, 2022 Share Posted July 6, 2022 Create override for attribute reference ./classes/Product.php This is a function public static function duplicateAttributes($id_product_old, $id_product_new) If you need to change the reference code only for the product, just create an override ./controllers/admin/AdminProductsController.php This is a function public function processDuplicate() Here you can add your own reference code generation function. E.g. public function generateRandomString($id_product = NULL,$length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } if ($id_product) { return Db::getInstance()->update('product', array('reference' => pSQL(generateRandomString($id_product)), 'id_product' => (int)$id_product); } else { return; } } /* and change duplicate function */ public function processDuplicate() { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { $id_product_old = $product->id; if (empty($product->price) && Shop::getContext() == Shop::CONTEXT_GROUP) { $shops = ShopGroup::getShopsFromGroup(Shop::getContextShopGroupID()); foreach ($shops as $shop) { if ($product->isAssociatedToShop($shop['id_shop'])) { $product_price = new Product($id_product_old, false, null, $shop['id_shop']); $product->price = $product_price->price; } } } unset( $product->id, $product->id_product ); $product->indexed = 0; $product->active = 0; if ($product->add() /* start here */ && $this->generateRandomString($product->id) /* end here */ && Category::duplicateProductCategories($id_product_old, $product->id) && Product::duplicateSuppliers($id_product_old, $product->id) && ($combination_images = Product::duplicateAttributes($id_product_old, $product->id)) !== false && GroupReduction::duplicateReduction($id_product_old, $product->id) ... ... ... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now