Jump to content
thirty bees forum

Question

Posted

Hi around the time I updated to 1.1.0 many images became unusable by the system and now just have camera image placeholders throughout the site.

Uploading new replacement images doesn't help.

Ive tried regenerating thumbnails and the .htaccess file

The process is that Im uploading product images, they upload fine, but then show as camera image placeholders in the back office.

Sometimes they appear fine on the front office, sometimes not.

Thinking its possibly something to do with Image Generation, Ive attached two pictures here of my image management section

 

 

Capture.PNG

Capture1.PNG

Recommended Posts

  • 0
Posted (edited)

@Mark, you are correct in what you are doing.  You have a problem you cant figure out, you goto the forums and try and get help.  Keep up the good fight!  You'll get this figured out....

Edited by SLiCK_303
  • 0
Posted

I've just checked @Traumflug's commit, and it did not fix the problem at hand.

@Mark edit file /classes/ImageType.php, find function getFormatedName, and insert following code just before // Give up searching:

        // if $name contains _default suffix, ie. home_default then try to resolve the name without this suffix
        $pos = strpos($name, '_default');
        if ($pos === strlen($name) - 8) {
            return static::getFormatedName(substr($name, 0, $pos));
        }

The result should looks like this:

image.png.f6180c264a4639cd6d88ff64dbf62799.png

  • 0
Posted

I told why I cancelled your back office access @zen and you seemed fine with that at the time. It was cancelled because Traumflug was working on the code to fix it for everyone and there would be no need for you or I to try and change the back office or codebase when the proper solution was close at hand.

Within hours of that, Traumflug did correct the code and it was the right decision to not spend time trying to change the codebase or back office settings adhoc in a potentially hazardous fashion.

 

Despite having done a bleeding edge update yesterday @datakickmy ImageType.php file doesnt resemble yours.

 

This is what I have

 

<?php
/**
 * 2007-2016 PrestaShop
 *
 * thirty bees is an extension to the PrestaShop e-commerce software developed by PrestaShop SA
 * Copyright (C) 2017-2018 thirty bees
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://www.thirtybees.com for more information.
 *
 * @author    thirty bees <[email protected]>
 * @author    PrestaShop SA <[email protected]>
 * @copyright 2017-2018 thirty bees
 * @copyright 2007-2016 PrestaShop SA
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 *  PrestaShop is an internationally registered trademark & property of PrestaShop SA
 */

/**
 * Class ImageTypeCore
 *
 * @since 1.0.0
 */
class ImageTypeCore extends ObjectModel
{
    // @codingStandardsIgnoreStart
    /**
     * @var array Image types cache
     */
    protected static $images_types_cache = [];
    /** @var array $images_types_name_cache */
    protected static $images_types_name_cache = [];
    /** @var string Name */
    public $name;
    /** @var int Width */
    public $width;
    /** @var int Height */
    public $height;
    /** @var bool Apply to products */
    public $products;
    /** @var int Apply to categories */
    public $categories;
    /** @var int Apply to manufacturers */
    public $manufacturers;
    /** @var int Apply to suppliers */
    public $suppliers;
    /** @var int Apply to scenes */
    public $scenes;
    /** @var int Apply to store */
    public $stores;
    // @codingStandardsIgnoreEnd

    /**
     * @see ObjectModel::$definition
     */
    public static $definition = [
        'table'   => 'image_type',
        'primary' => 'id_image_type',
        'fields'  => [
            'name'          => ['type' => self::TYPE_STRING, 'validate' => 'isImageTypeName', 'required' => true, 'size' => 64],
            'width'         => ['type' => self::TYPE_INT, 'validate' => 'isImageSize', 'required' => true],
            'height'        => ['type' => self::TYPE_INT, 'validate' => 'isImageSize', 'required' => true],
            'categories'    => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'products'      => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'manufacturers' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'suppliers'     => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'scenes'        => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
            'stores'        => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
        ],
    ];

    protected $webserviceParameters = [];

    /**
     * Returns image type definitions
     *
     * @param string|null $type Image type
     * @param bool        $orderBySize
     *
     * @return array Image type definitions
     * @throws PrestaShopDatabaseException
     *
     * @since   1.0.0
     * @version 1.0.0 Initial version
     * @throws PrestaShopException
     */
    public static function getImagesTypes($type = null, $orderBySize = false)
    {
        // @codingStandardsIgnoreStart
        if (!isset(static::$images_types_cache[$type])) {
            $query = (new DbQuery())
                ->select('*')
                ->from('image_type');
            if (!empty($type)) {
                $query->where('`'.bqSQL($type).'` = 1');
            }

            if ($orderBySize) {
                $query->orderBy('`width` DESC, `height` DESC, `name` ASC');
            } else {
                $query->orderBy('`name` ASC');
            }

            static::$images_types_cache[$type] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
        }

        return static::$images_types_cache[$type];
        // @codingStandardsIgnoreEnd
    }

    /**
     * Check if type already is already registered in database
     *
     * @param string $typeName Name
     *
     * @return int Number of results found
     *
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     * @since   1.0.0
     * @version 1.0.0 Initial version
     */
    public static function typeAlreadyExists($typeName)
    {
        if (!Validate::isImageTypeName($typeName)) {
            die(Tools::displayError());
        }

        Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
            (new DbQuery())
                ->select('`id_image_type`')
                ->from('image_type')
                ->where('`name` = \''.pSQL($typeName).'\'')
        );

        return Db::getInstance()->NumRows();
    }

    /**
     * @param string $name
     *
     * @return string
     *
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     * @since   1.0.0
     * @version 1.0.0 Initial version
     */
    public static function getFormatedName($name)
    {
        $themeName = Context::getContext()->shop->theme_name;
        $nameWithoutThemeName = str_replace(['_'.$themeName, $themeName.'_'], '', $name);

        //check if the theme name is already in $name if yes only return $name
        if (strstr($name, $themeName) && static::getByNameNType($name)) {
            return $name;
        } elseif (static::getByNameNType($nameWithoutThemeName.'_'.$themeName)) {
            return $nameWithoutThemeName.'_'.$themeName;
        } elseif (static::getByNameNType($themeName.'_'.$nameWithoutThemeName)) {
            return $themeName.'_'.$nameWithoutThemeName;
        } else {
            return $nameWithoutThemeName.'_default';
        }
    }

    /**
     * Finds image type definition by name and type
     *
     * @param string $name
     * @param string $type
     *
     * @param int    $order
     *
     * @return bool|mixed
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     * @since   1.0.0
     * @version 1.0.0 Initial version
     */
    public static function getByNameNType($name, $type = null, $order = 0)
    {
        static $isPassed = false;

        // @codingStandardsIgnoreStart
        if (!isset(static::$images_types_name_cache[$name.'_'.$type.'_'.$order]) && !$isPassed) {
            $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM `'._DB_PREFIX_.'image_type`');

            $types = ['products', 'categories', 'manufacturers', 'suppliers', 'scenes', 'stores'];
            $total = count($types);

            foreach ($results as $result) {
                foreach ($result as $value) {
                    for ($i = 0; $i < $total; ++$i) {
                        static::$images_types_name_cache[$result['name'].'_'.$types[$i].'_'.$value] = $result;
                    }
                }
            }

            $isPassed = true;
        }

        $return = false;
        if (isset(static::$images_types_name_cache[$name.'_'.$type.'_'.$order])) {
            $return = static::$images_types_name_cache[$name.'_'.$type.'_'.$order];
        }
        // @codingStandardsIgnoreEnd

        return $return;
    }
}

 

  • 0
Posted (edited)

Note for anyone looking at my site and seeing I have images: I have temporarily reverted to Stable version of 1.1.0 which does present most but not all of the images while we complete this last piece of the puzzle, in order that customers, in the main, can do their thing....

Edited by Mark
  • 0
Posted
2 hours ago, datakick said:

I've just checked @Traumflug's commit, and it did not fix the problem at hand.

Well, it fixed the problem I found in my development installation. Looks like there's more than one problem involved here. Or I fixed something else, not the issue here.

  • 0
Posted

Looking at this page, one image is missing:

https://product.solutions.org.nz/remote-car-alarm-with-central-locking-and-engine-disable

Digging a bit deeper, this is the image URL:

https://product.solutions.org.nz/194-community-theme-default_cart_default/remote-car-alarm-with-central-locking-and-engine-disable.jpg

This URL looks fine to me. Shop is apparently using theme community-theme-default, this theme has the old image type names (with _default), so that's what's expected. Also, some other images work, which makes a glitch in image finding unlikely. Broken code usually applies to all images, not just a few.

I'd start looking at which images are actually on disk. This image should be in img/p/1/9/4/ and next to index.php and the original file, 194.jpg, there should be one additional file for each image type. Similar to this (this is for image no. 21):

21-community-theme-default_cart_default.jpg  
21-community-theme-default_home_default.jpg  
21-community-theme-default_home_default_smaller.jpg  
21-community-theme-default_home_default_smallest.jpg  
21-community-theme-default_large_default.jpg  
21-community-theme-default_medium_default.jpg  
21-community-theme-default_small_default.jpg  
21-community-theme-default_thickbox_default.jpg  
21.jpg  
21-Niara_cart.jpg  
21-Niara_home.jpg  
21-Niara_home_smaller.jpg  
21-Niara_home_smallest.jpg  
21-Niara_large.jpg  
21-Niara_medium.jpg  
21-Niara_small.jpg  
21-Niara_thickbox.jpg  
index.php
  • 0
Posted

P.S.: I'd also download a few images and open them in an image viewer to find out whether they're actually JPEGs (or PNGs with suffix .jpg). I've seen shop installations where properly named files were there, but none of them being actual images.

  • 0
Posted (edited)

Thanks @datakick I have now updated to Bleeding Edge 1.1.0 , great spotting.

Things seem to ok at first glance at the moment, and images that werent working before under Stable1.1.0 are now there

Now I'll do what @Traumflugsuggests and look closely at any remaining problem images and replace them and look for anything else.

Thank you all. 

 

Brilliant Core Updater process by the way, love that its so easy to change versions.

 

Edited by Mark
  • 0
Posted
8 hours ago, Traumflug said:

Well, it fixed the problem I found in my development installation. Looks like there's more than one problem involved here. Or I fixed something else, not the issue here.

@Traumflug you are right. Your commit fixes the problem if you use .jpg / .png files. I'm using .webp and for those the code in PageNotFoundController does not work. I've created the pull request to add .webp support: https://github.com/thirtybees/thirtybees/pull/1063

I have also reopened my original pull request https://github.com/thirtybees/thirtybees/pull/1057. It is somewhat redundant now, but I still think it's a good to have. Let me explain what happens if some module wrongly uses hardcoded image type 'home_default': 

Current situation:

  1. the html output will contain image link in a format 'http://domain.com/111-home_default/product-name.jpg'
  2. because home_default type does not exists, this request will be handled by PageNotFoundController
  3. controller will be able to re-map image type 'home_default' to 'home', and return correct image

With my pull request:

  1. the html output will already contain correct image link: 'http://domain.com/111-home/product-name.jpg'
  2. if image exists, apache/nginx will return it directly without involving php

So, basically, this pull request saves some php processing time, and allows for better static assets optimization

  • Like 1
  • 0
Posted

2 years later....

Just installed tb 1.1, which installs the niary theme and default theme on standard.
So far so good.

But, i want to work with the panda theme, tb version.
As soon as i upload the panda theme, the problem persists wqith empty backoffice images because it still links to the old (default or niara) theme.

i have tried everything i can think of, replace images, re generate images, delete cache, enter new images - nothing works.

Any one can point me in the right direction?

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...