Jump to content

[Solved] - Save special characteres in UTF-8 problem, override function productImport


Reco-X

Recommended Posts

Hello, Im doing a modification for the function productImport from the class AdminImportController, and my problem its that made a function that auto fills some fields of the product but in certain cases the data has strange characteres and its not allowed to save it with the good encode.

This string is saved in the database ø instead of ø

 

My database is UTF-8 and also if I insert manually that kind of characters it works.

 

So  afters the link arrayWalk i put my custom code.

AdminImportController::setEntityDefaultValues($product);
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);

if (isset($product->imdb_link)) {
    $product = $this->getMovieInformation($product);
}

The problem is if I do a die(var_dump($product));

it seems every single properties of the object correctly, but I dont know exactly where in the code do the connection to the database for save this item.

Here is how I fill the data with my function

    private function getMovieInformation($product) {
        if (isset($product->imdb_link)){
            $imdb = new Imdb();
            $idMovie = $this->getIdMovieFromString($product->imdb_link);
            $info = $imdb->getMovieInfo($idMovie);

            if (!($info['error'])){
                $product->actors = '';
                $product->director = '';
                $product->country = '';
                $product->original_name = '';
                $product->description = '';
                $product->year = '';
                $product->duration = '';
                $product->imdb_link = '';

                $product->original_name = utf8_encode($info['title']);
                $product->description = utf8_encode($info['storyline']);
                $product->year = utf8_encode($info['year']);
                $product->duration = utf8_encode($info['runtime']) .' min';
                $product->imdb_link = utf8_encode($info['imdb_url']);

                foreach ($info['cast'] as $actor){
                    $product->actors .= ', '.utf8_encode($actor);
                }
                $product->actors = substr($product->actors, 2);

                foreach ($info['directors'] as $director){
                    $product->director .= ', '.utf8_encode($director);
                }
                $product->director = substr($product->director, 2);

                foreach ($info['country'] as $country){
                    $product->country .= ', '.utf8_encode($country);
                }
                $product->country = substr($product->country, 2);
            }
		}
        return $product;
    }

private function getIdMovieFromString($string) {
     $string = strstr($string,'title/');
     return substr($string, 6,9);
}

Thanks for the help.

Edited by Reco-X (see edit history)
Link to comment
Share on other sites

Also I tried to put the function

$product->country = $this->utf8EncodeArray($product->country);

But the thing I dont get is why when the characters come from the csv file it works, but when I put it from the scrapper no.

Link to comment
Share on other sites

  • 2 weeks later...

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