Duplicating products



  • There are a couple problems, at least these two, that happen when you duplicate a product. The specific prices and downloads(attachements) are not duplicated. They are supposed to be, if you look at the code in controllers/admin/AdminProductsController.php, via this block of code, and the associated functions in classes/Product.php…

    if ($product->add()
                    && Category::duplicateProductCategories($idProductOld, $product->id)
                    && Product::duplicateSuppliers($idProductOld, $product->id)
                    && ($combinationImages = Product::duplicateAttributes($idProductOld, $product->id)) !== false
                    && GroupReduction::duplicateReduction($idProductOld, $product->id)
                    && Product::duplicateAccessories($idProductOld, $product->id)
                    && Product::duplicateFeatures($idProductOld, $product->id)
                    && Product::duplicateSpecificPrices($idProductOld, $product->id)
                    && Pack::duplicate($idProductOld, $product->id)
                    && Product::duplicateCustomizationFields($idProductOld, $product->id)
                    && Product::duplicateTags($idProductOld, $product->id)
                    && Product::duplicateDownload($idProductOld, $product->id)
                ) {
    

    …but they don’t get duplicated.



  • After looking into it a bit more, a ‘download’ is NOT an ‘attachment’. Sorry for my confusion. So it’s not duplicating that because it’s not told to. I will add it to the above code and see if it does duplicate attachments or not.

    edit: yes it does duplicate attachments if it’s told to. Just put this in the code after…

                    && Product::duplicateDownload($idProductOld, $product->id)
    

    add…

                    && Product::duplicateAttachments($idProductOld, $product->id)
    

    So that can be done with an override, but I think it should be done to the core.



  • Why duplicateSpecificPrices isn’t working is beyond me. I can look at the function and tell it wont work, but as to making it work, is way above my paygrade.



  • I think I fixed it…amazing no? At any rate, in /classes/Product.php, find…

    foreach (SpecificPrice::getIdsByProductId((int) $oldProductId) as $data) {
    

    change to…

    foreach (SpecificPrice::getByProductId((int) $oldProductId) as $data) {
    

    I’ll keep testing to make sure it’s working… I’ll get back to ya…

    edit: seems to be working for me, try it yourself and let me know. I’m sure I’m not the only person who had issue with this not working. Again I could make this an override, but it needs to be fixed in the core instead.



  • I forked, and made a pull request for both of these issues…


 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.