Attachments not visible in product backoffice



  • When i go to backoffice in Thirtybees 1.0.3 and upload an attachment in “Catalog - Attachments”, i am not able to find the uploaded attachment when i go to a product and would like to choose the recent uploaded attachment.

    If i dublicate a product with an attachment, the attachment disappears on the new product.
    If i try to upload the attachment manually in each product, it works fine.

    0_1509091550039_Print screen.png

    Problem solved 02.01.2018 by following @SLiCK_303’s suggestion by replacing the code below in “Classes/Attachment.php”

    Replace:

    public static function getAttachments($idLang, $idProduct, $include = true)
    {
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
            (new DbQuery())
                ->select('a.*, al.*')
                ->from('attachment', 'a')
                ->leftJoin('attachment_lang', 'al', 'a.`id_attachment` = al.`id_attachment`')
                ->leftJoin('product_attachment', 'pa', 'pa.`id_attachment` = a.`id_attachment`')
                ->where('al.`id_lang` = '.(int) $idLang)
                ->where($include ? 'pa.`id_product` = '.(int) $idProduct : '')
                ->where('pa.`id_product` IS '.($include ? 'NOT ' : '').'NULL')
        );
    }
    

    with:

    public static function getAttachments($idLang, $idProduct, $include = true)
    {
        return Db::getInstance()->executeS('
            SELECT *
            FROM '._DB_PREFIX_.'attachment a
            LEFT JOIN '._DB_PREFIX_.'attachment_lang al
                ON (a.id_attachment = al.id_attachment AND al.id_lang = '.(int) $idLang.')
            WHERE a.id_attachment '.($include ? 'IN' : 'NOT IN').' (
                SELECT pa.id_attachment
                FROM '._DB_PREFIX_.'product_attachment pa
                WHERE id_product = '.(int) $idProduct.'
            )'
        );
    }


  • Yes dublicates loses the attachments but the main problem is that attachments uploaded in “Catalog - Attachments” can’t be chosen afterwards in the products, which is a problem if you would like to use the same attachment for several products.

    The print screen in the top is an example of how it looks when i edit a product and would like to choose an attachment i already have uploaded, then i can’t find the attachment.



  • Sounds great, thank you 🙂



  • Hi, Is there any progress on this “Attachments not visible in product backoffice” issue? Or is there a workround/permissions thing I can use? This is a pretty serious issue for me. I have been using Prestashop on projects until now but don’t like the way things are going. so I thought I would try 30b… This problem is the only issue that has affected me so far and it affects us pretty seriously.



  • Works fine for me, in both 1.0.3 and in 1.0.4. Except for when you duplicate the product, then the attachment doesn’t come along, but then again neither do specific prices so…



  • I see the problem, once the attachment is used for one product, you can’t pick it again for another product.



  • Hi @mdekker
    Have there been found a solution for the problem posted 27th October?



  • The issue I see has to do with /classes/Attachment.php. If I take the one outta ps1.6.1.17, it lets me pick the same attachment for any/all products. As I’m not sure the ramifications of swapping out that file, I don’t recommend this as a fix, but rather a starting point to troubleshoot the issue.



  • it happens in 1.0.3 and my latest source site



  • Thanks for the responses and i am sorry if I was not as detailed as I could have been. To reproduce:

    1. Create an attachment document using: Catalog ->Attachments -> Add new attachment
    2. Create a new product using: Catalog -> Products -> Add new product
    3. Save the product
    4. Attach the document created in step 1 above

    My Outcome: The attachment created in step 1 is not visible and so cannot be attached
    Sometimes it is visible for the first product created but not for any subsequent products

    Thanks



  • The problem lies in the /classes/Attachments.php file, in the getAttachments function. If I replace just that function with the one outta PS 1.6.1.17’s file, it works.



  • no,no…you need to re-write that sql statement in tb 1.0.4 format, not leave it in the old school way… 😉



  • replace…

        public static function getAttachments($idLang, $idProduct, $include = true)
        {
            return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                (new DbQuery())
                    ->select('a.*, al.*')
                    ->from('attachment', 'a')
                    ->leftJoin('attachment_lang', 'al', 'a.`id_attachment` = al.`id_attachment`')
                    ->leftJoin('product_attachment', 'pa', 'pa.`id_attachment` = a.`id_attachment`')
                    ->where('al.`id_lang` = '.(int) $idLang)
                    ->where($include ? 'pa.`id_product` = '.(int) $idProduct : '')
                    ->where('pa.`id_product` IS '.($include ? 'NOT ' : '').'NULL')
            );
        }
    

    with…

        public static function getAttachments($idLang, $idProduct, $include = true)
        {
            return Db::getInstance()->executeS('
                SELECT *
                FROM '._DB_PREFIX_.'attachment a
                LEFT JOIN '._DB_PREFIX_.'attachment_lang al
                    ON (a.id_attachment = al.id_attachment AND al.id_lang = '.(int) $idLang.')
                WHERE a.id_attachment '.($include ? 'IN' : 'NOT IN').' (
                    SELECT pa.id_attachment
                    FROM '._DB_PREFIX_.'product_attachment pa
                    WHERE id_product = '.(int) $idProduct.'
                )'
            );
        }
    

    If you didn’t have those two files handy…
    edit: I modified the first two variables, just to make it more a little more current. It would be nice if it was re-written with the (new DbQuery()) type… hint hint, nudge nudge… 😉



  • Thank you everyone,

    I have replaced the public static function getAttachments (found in /classes/Attachment.php) with the function as suggested by SLiCK_303 and all is working perfectly.

    For me this problem appears solved for the current version. I am guessing that this will be integrated into the development cycle for future versions. I have just checked the github version and it is still at the old version. I am not a code contributor so I cannot do this.

    John



  • Thank you all 🙂
    Problem has been solved with @SLiCK_303’s suggestion.

    How do i mark the topic as solved?
    0_1514893810694_printscreen.png



  • Click on the three little vertical dots on the bottom right of one of your posts…


 

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