Jump to content

Categories Image propagation


Recommended Posts

Hey people,

 

I'm developing a simple module which pretends to mantain the control of all the products with categories. When user adds new category on "Control", it gets created below all the others lvl 3 categories with different id but the same name.

 

The problem becomes when I try to use the same image used on the "Control" class on all subclasses created. I've been trying things like:

$category->id_image = $params['category']->id;

Bcoz of this on Category.php

/** @var string id_image is the category ID when an image exists and 'default' otherwise */
    public $id_image = 'default';

This attribute gets updated when I prepare it before upload but when I save it dissapear and I'm wondering why.

 

If somewone could just answer why it happends or some possible solution would be awesome! Thanks!! 

Link to comment
Share on other sites

  • 2 weeks later...
Please refer to the code below (its the constructor of Category class)

 


public function __construct($id_category = null, $id_lang = null, $id_shop = null)

    {

        parent::__construct($id_category, $id_lang, $id_shop);

        $this->id_image = ($this->id && file_exists(_PS_CAT_IMG_DIR_.(int)$this->id.'.jpg')) ? (int)$this->id : false;

        $this->image_dir = _PS_CAT_IMG_DIR_;

    }


 

 

If you can notice the second line in the function, you will realize that it actually checks if the file actually exists. 

 

It might be possible that the image that you are assigning doesn't actually exist, please verify the same.

Edited by Knowband Plugins (see edit history)
Link to comment
Share on other sites

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...