Occasionally I've had issues where an image doesn't download properly from shopify. When this happens there are no protections to gracefully deal with the fail and the sync stops.

CommentFileSizeAuthor
#8 yH5N.jpg26.28 KBtseven
#2 Screen Shot 2015-09-01 at 9.13.09 AM.png50.71 KBjh sio
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

John Carbone’s picture

Status: Active » Postponed (maintainer needs more info)

Please provide steps to reproduce.

jh sio’s picture

Drupal version 7.39
Module version 7.x-1.0-alpha7

Product syncing when there is an image fails every time for me.
It appears to be failing at entity creation. Attached screenshot of error.

But, root cause seems to be line 314 in shopify.entity.inc. system_retrieve_file fails and returns FALSE, so passing that onto entity api is also failing.

Edit: Okay, it appears to only fail when retrieving images from https protocol.

jh sio’s picture

jh sio’s picture

I solved my problem by using curl instead.

Changed shopify.entity.inc, line 314 from

$file = system_retrieve_file($product_image['src'], $directory, TRUE, FILE_EXISTS_REPLACE);

to

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_FAILONERROR => 1,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $product_image['src'],
));
$resp = curl_exec($curl);
curl_close($curl);        
$file = file_save_data($resp, $directory);
if (!$file) {
  drupal_set_message(t('Shopify image could not be saved to @path.', array('@path' => $directory)), 'error');
}
jh sio’s picture

mathiasha’s picture

I get same the exact same error when trying to sync.
Changing shopify.entity.inc as jh sio suggested didn't make any difference.

The error started occurring after changed the variants some products on Shopify, but I don't know if that is what caused the problem.

mathiasha’s picture

I seem to have found what caused the problem.
I had set the Shopify Product Images field settings to only allow 1 value, changing it to unlimited values fixed the problem.

tseven’s picture

FileSize
26.28 KB

I've experienced the same issue.

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=9&op=do StatusText: Service unavailable (with message) ResponseText: EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityMetadataWrapper->set() (line 122 of /Volumes/Other_Stuff/htdocs/php/shopify.my/sites/all/modules/entity/includes/entity.wrapper.inc).

I was unable to complete a sync until I applied jh sio's curl work-a-around.

Here is a modified version which uses curl if available and falls back to the old way otherwise:

        if (extension_loaded('curl') === true){
          $curl = curl_init();
          curl_setopt_array($curl, array(
            CURLOPT_FAILONERROR    => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL            => $product_image['src'],
          ));
          $resp = curl_exec($curl);
          curl_close($curl);
          $file = file_save_data($resp, $directory);
          if (!$file) {
            drupal_set_message(t('Shopify image could not be saved to @path.', array('@path' => $directory)), 'error');
          }
        }else{
          $file = system_retrieve_file($product_image['src'], $directory, TRUE, FILE_EXISTS_REPLACE);
        }

  • donutdan4114 committed 3f1fef1 on 7.x-1.x
    Issue #2543134: Fix sync crash by using curl to download images by...
donutdan4114’s picture

Version: 7.x-1.0-alpha7 » 7.x-1.x-dev
Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

tseven’s picture

Status: Closed (fixed) » Fixed

The fix in #4 again referenced #8 does fix the download error but it leaves the files with temporary file names.

The modified code below fixes that issue:

if (extension_loaded('curl') === TRUE) {
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_FAILONERROR => 1,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => $product_image['src'],
    ));
    $resp = curl_exec($curl);
    curl_close($curl);

    $file_name = drupal_basename($product_image['src']);
    /* remove the cache busting ?v=2938827 */
    $file_name = preg_replace("/\?.+/", '', $file_name);
    $file_path = "$directory/$file_name";

    $file = file_save_data($resp, $file_path);

    if (!$file) {
        drupal_set_message(t('Shopify image could not be saved to @path.', array('@path' => $directory)), 'error');
    }
} else {
    $file = system_retrieve_file($product_image['src'], $directory, TRUE, FILE_EXISTS_REPLACE);
}

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.