Jump to content

Edit History

knacky

knacky

./override/classes/Product.php

This code does not copy any images.
It finds out the ID of the products in the package and creates a simple SQL query to the database and returns the ID of the images of the individual products !!!

You can also edit the code so that it only shows images of the variant in the package.

Just load the id_product_attribute item and find out the image of the attribute / combination.

class Product extends ProductCore
{


    public function getImages($id_lang, Context $context = null)
    {

        $productsInPack = array();

        if (Pack::isPack((int) $this->id)) {

            $getProductInPack = Db::getInstance()->executeS('SELECT id_product_item FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.$this->id.' GROUP BY id_product_item');

            if ($getProductInPack){
                foreach ($getProductInPack as $productPack){
                    $productsInPack[] = $productPack['id_product_item'];
                }
            }
        }


        if ($productsInPack){
            $getProducts = implode(', ', $productsInPack);
        } else {
            $getProducts = $this->id;
        }

        $query = '
        SELECT image_shop.`cover`, i.`id_image`, il.`legend`, i.`position`
        FROM `' . _DB_PREFIX_ . 'image` i
        ' . Shop::addSqlAssociation('image', 'i') . '
        LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
        WHERE i.`id_product` IN (' . $getProducts . ')
        ORDER BY `position`';

        return Db::getInstance()->executeS($query);

    }

    

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, \Context $context = null) 
    {
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
}

 

BO:

obrazek.thumb.png.20b63d62aba1ff31cab5a87fcfd2d585.png

 

FO:

obrazek.png.6f571fed1f0f98f4b9229987e055e8b1.png

knacky

knacky

./override/classes/Product.php

This code does not copy any images.
It finds out the ID of the products in the package and creates a simple SQL query to the database and returns the ID of the images of the individual products !!!

You can also edit the code so that it only shows images of the variant in the package.

class Product extends ProductCore
{


    public function getImages($id_lang, Context $context = null)
    {

        $productsInPack = array();

        if (Pack::isPack((int) $this->id)) {

            $getProductInPack = Db::getInstance()->executeS('SELECT id_product_item FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.$this->id.' GROUP BY id_product_item');

            if ($getProductInPack){
                foreach ($getProductInPack as $productPack){
                    $productsInPack[] = $productPack['id_product_item'];
                }
            }
        }


        if ($productsInPack){
            $getProducts = implode(', ', $productsInPack);
        } else {
            $getProducts = $this->id;
        }

        $query = '
        SELECT image_shop.`cover`, i.`id_image`, il.`legend`, i.`position`
        FROM `' . _DB_PREFIX_ . 'image` i
        ' . Shop::addSqlAssociation('image', 'i') . '
        LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
        WHERE i.`id_product` IN (' . $getProducts . ')
        ORDER BY `position`';

        return Db::getInstance()->executeS($query);

    }

    

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, \Context $context = null) 
    {
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
}

 

BO:

obrazek.thumb.png.20b63d62aba1ff31cab5a87fcfd2d585.png

 

FO:

obrazek.png.6f571fed1f0f98f4b9229987e055e8b1.png

knacky

knacky

./override/classes/Product.php

This code does not copy any images.
It finds out the ID of the products in the package and creates a simple SQL query to the database and returns the ID of the images of the individual products !!!

class Product extends ProductCore
{


    public function getImages($id_lang, Context $context = null)
    {

        $productsInPack = array();

        if (Pack::isPack((int) $this->id)) {

            $getProductInPack = Db::getInstance()->executeS('SELECT id_product_item FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.$this->id.' GROUP BY id_product_item');

            if ($getProductInPack){
                foreach ($getProductInPack as $productPack){
                    $productsInPack[] = $productPack['id_product_item'];
                }
            }
        }


        if ($productsInPack){
            $getProducts = implode(', ', $productsInPack);
        } else {
            $getProducts = $this->id;
        }

        $query = '
        SELECT image_shop.`cover`, i.`id_image`, il.`legend`, i.`position`
        FROM `' . _DB_PREFIX_ . 'image` i
        ' . Shop::addSqlAssociation('image', 'i') . '
        LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
        WHERE i.`id_product` IN (' . $getProducts . ')
        ORDER BY `position`';

        return Db::getInstance()->executeS($query);

    }

    

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, \Context $context = null) 
    {
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
}

 

BO:

obrazek.thumb.png.20b63d62aba1ff31cab5a87fcfd2d585.png

 

FO:

obrazek.png.6f571fed1f0f98f4b9229987e055e8b1.png

knacky

knacky

./override/classes/Product.php

This code does not copy any images.
It finds out the ID of the products in the package and creates a simple SQL query to the database and returns the ID of the images of the individual products !!!

class Product extends ProductCore
{


    public function getImages($id_lang, Context $context = null)
    {

        $productsInPack = array();

        if (Pack::isPack((int) $this->id)) {

            $getProductInPack = Db::getInstance()->executeS('SELECT id_product_item FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.$this->id.' GROUP BY id_product_item');

            if ($getProductInPack){
                foreach ($getProductInPack as $productPack){
                    $productsInPack[] = $productPack['id_product_item'];
                }
            }
        }


        if ($productsInPack){
            $getProducts = implode(', ', $productsInPack);
        } else {
            $getProducts = $this->id;
        }

        $query = '
        SELECT image_shop.`cover`, i.`id_image`, il.`legend`, i.`position`
        FROM `' . _DB_PREFIX_ . 'image` i
        ' . Shop::addSqlAssociation('image', 'i') . '
        LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
        WHERE i.`id_product` IN (' . $getProducts . ')
        ORDER BY `position`';

        file_put_contents(_PS_ROOT_DIR_.'/override/classes/Product.txt', $query);

        return Db::getInstance()->executeS($query);

    }

    

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, \Context $context = null) 
    {
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
}

 

BO:

obrazek.thumb.png.20b63d62aba1ff31cab5a87fcfd2d585.png

 

FO:

obrazek.png.6f571fed1f0f98f4b9229987e055e8b1.png

×
×
  • Create New...