Anonymous
Не загружать изображения в магазин etsy с помощью RSS-канала, если указан относительный путь.
Сообщение
Anonymous » 16 окт 2024, 06:53
Я пытаюсь создать каналы для имеющихся у меня продуктов и поделиться ими в магазине etsy. Для этого я сделал следующие вещи. Функция для выполнения этой задачи:
Для отправки списка продуктов:
Код: Выделить всё
function submit_listing_to_etsy()
{
global $wpdb;
$table = $wpdb->prefix . "etcpf_listings";
$id = false;
if ($this->check_unsubmitted_listing()) {
$id = $this->listing['id'];
$data = maybe_unserialize($this->listing['data']);
$listing_id = '';
$type = false;
if (!(NULL == $this->listing['listing_id'])) {
$listing_id = '/'.$this->listing['listing_id'];
$type = true;
}
unset($data['image']);
if (isset($data['sku'])) {
unset($data['sku']); // it is not supported yet
}
unset($data['image']);
if (count($data['tags']) == 1) { // check if tags with 0 value is set
unset($data['tags']);
}
$weight = explode(' ', $data['item_weight']);
if (isset($weight[1])) {
$data['item_weight'] = $weight[0];
$data['item_weight_units'] = $weight[1];
}
$length = explode(' ',$data['item_length']);
if (isset($length[1])) {
$data['item_length'] = $length[0];
$data['item_length_units'] = $length[1];
}
$width = explode(' ',$data['item_width']);
if (isset($width[1])) {
$data['item_width'] = $width[0];
$data['item_width_units'] = $width[1];
}
$height = explode(' ',$data['item_height']);
if (isset($height[1])) {
$data['item_height'] = $height[0];
$data['item_height_units'] = $height[1];
}
$data['language'] = substr(get_locale(), 0,2);
$url = "https://openapi.etsy.com/v2/listings".$listing_id."?scopes=listings_w";
$acc_req = $this->prepareHash($url,'POST',$type);
// $response = $this->browsePost($acc_req,json_encode($data),true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $acc_req);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response);
$result = $result->results;
$listing = $result[0];
$this->listing_id = $listing->listing_id;
if ($this->listing_id) {
$data = [
'listing_id' => $this->listing_id,
'upload_result' => maybe_serialize($listing),
'uploaded' => (strlen($listing_id) > 0) ? 2 : 1
];
} else
$data = [
'upload_result' => maybe_serialize($response),
'uploaded' => 3
];
$wpdb->update($table,$data,['id'=>$id]);
}
}
Для отправки изображений этих продуктов:
Код: Выделить всё
function submit_listing_images(){
$data = maybe_unserialize($this->listing['data']);
$image = $data['image'];
global $wpdb;
$tbl = $wpdb->prefix . "etcpf_listings";
$this->check_unsubmitted_listing(1);
$url = "https://openapi.etsy.com/v2/listings/".$this->listing['listing_id']."/images";
$wp_dir = wp_upload_dir();
$i = str_replace($wp_dir['url'],$wp_dir['path'],$image);
if ($i == $image)
$i = str_replace($wp_dir['baseurl'], $wp_dir['basedir'], $image);
$img_type = wp_check_filetype($image);
$url_to_send = $this->prepareHash($url,'POST');
$data = [
'image' => '@'.$i.';type='.$img_type['type']
];
if (!$i) {
$wpdb->update($tbl,['uploaded' => 2],['id'=>$this->listing['id']]);
return;
}
//print_r($data);exit;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_to_send);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: multipart/form-data"]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response);
$result = $result->results;
$img_data = $result[0];
$listing_image_id = $img_data->listing_image_id;
if ($listing_image_id) {
$wpdb->update($tbl,['listing_image_id'=>$listing_image_id,'uploaded' => 2],['id'=>$this->listing['id']]);
}
}
Сгенерированные каналы выглядят следующим образом:
Код: Выделить всё
test
...
41
40
10
35.00
http://localhost/wordpress/wp-content/uploads/2013/06/hoodie_7_front.jpg
kg
cm
NPR
42
40
10
35.00
http://localhost/wordpress/wp-content/uploads/2013/06/hoodie_1_front.jpg
30.00
kg
cm
NPR
47
10
35.00
http://localhost/wordpress/wp-content/uploads/2013/06/hoodie_2_front.jpg
kg
cm
NPR
Путь в этом сгенерированном канале правильный. Когда я копирую и вставляю путь к изображению, он загружает изображения. Но на etsy API отправляется относительный путь. Пока я печатаю данные, содержащие путь к изображению, он возвращает примерно такой массив:
Код: Выделить всё
Array ( [image] => @/var/www/html/wordpress/wp-content/uploads/2013/06/hoodie_1_front.jpg;type=image/jpeg )
И когда я проверяю его в соответствующей папке, конкретное изображение существует. Итак, может ли кто-нибудь помочь мне, в чем здесь реальная проблема? Интересно то, что иногда с какого-то компьютера также отправляется изображение, и оно отправляется в магазин etsy. В чем здесь реальная проблема? Заранее спасибо.
ЕСЛИ вы хотите понять что-нибудь еще. Пожалуйста, прокомментируйте.
Подробнее здесь:
https://stackoverflow.com/questions/480 ... h-is-given
1729050797
Anonymous
Я пытаюсь создать каналы для имеющихся у меня продуктов и поделиться ими в магазине etsy. Для этого я сделал следующие вещи. Функция для выполнения этой задачи: Для отправки списка продуктов: [code] function submit_listing_to_etsy() { global $wpdb; $table = $wpdb->prefix . "etcpf_listings"; $id = false; if ($this->check_unsubmitted_listing()) { $id = $this->listing['id']; $data = maybe_unserialize($this->listing['data']); $listing_id = ''; $type = false; if (!(NULL == $this->listing['listing_id'])) { $listing_id = '/'.$this->listing['listing_id']; $type = true; } unset($data['image']); if (isset($data['sku'])) { unset($data['sku']); // it is not supported yet } unset($data['image']); if (count($data['tags']) == 1) { // check if tags with 0 value is set unset($data['tags']); } $weight = explode(' ', $data['item_weight']); if (isset($weight[1])) { $data['item_weight'] = $weight[0]; $data['item_weight_units'] = $weight[1]; } $length = explode(' ',$data['item_length']); if (isset($length[1])) { $data['item_length'] = $length[0]; $data['item_length_units'] = $length[1]; } $width = explode(' ',$data['item_width']); if (isset($width[1])) { $data['item_width'] = $width[0]; $data['item_width_units'] = $width[1]; } $height = explode(' ',$data['item_height']); if (isset($height[1])) { $data['item_height'] = $height[0]; $data['item_height_units'] = $height[1]; } $data['language'] = substr(get_locale(), 0,2); $url = "https://openapi.etsy.com/v2/listings".$listing_id."?scopes=listings_w"; $acc_req = $this->prepareHash($url,'POST',$type); // $response = $this->browsePost($acc_req,json_encode($data),true); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $acc_req); curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response); $result = $result->results; $listing = $result[0]; $this->listing_id = $listing->listing_id; if ($this->listing_id) { $data = [ 'listing_id' => $this->listing_id, 'upload_result' => maybe_serialize($listing), 'uploaded' => (strlen($listing_id) > 0) ? 2 : 1 ]; } else $data = [ 'upload_result' => maybe_serialize($response), 'uploaded' => 3 ]; $wpdb->update($table,$data,['id'=>$id]); } } [/code] Для отправки изображений этих продуктов: [code] function submit_listing_images(){ $data = maybe_unserialize($this->listing['data']); $image = $data['image']; global $wpdb; $tbl = $wpdb->prefix . "etcpf_listings"; $this->check_unsubmitted_listing(1); $url = "https://openapi.etsy.com/v2/listings/".$this->listing['listing_id']."/images"; $wp_dir = wp_upload_dir(); $i = str_replace($wp_dir['url'],$wp_dir['path'],$image); if ($i == $image) $i = str_replace($wp_dir['baseurl'], $wp_dir['basedir'], $image); $img_type = wp_check_filetype($image); $url_to_send = $this->prepareHash($url,'POST'); $data = [ 'image' => '@'.$i.';type='.$img_type['type'] ]; if (!$i) { $wpdb->update($tbl,['uploaded' => 2],['id'=>$this->listing['id']]); return; } //print_r($data);exit; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url_to_send); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SAFE_UPLOAD, FALSE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: multipart/form-data"]); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response); $result = $result->results; $img_data = $result[0]; $listing_image_id = $img_data->listing_image_id; if ($listing_image_id) { $wpdb->update($tbl,['listing_image_id'=>$listing_image_id,'uploaded' => 2],['id'=>$this->listing['id']]); } } [/code] Сгенерированные каналы выглядят следующим образом: [code] test ... 41 40 10 35.00 http://localhost/wordpress/wp-content/uploads/2013/06/hoodie_7_front.jpg kg cm NPR 42 40 10 35.00 http://localhost/wordpress/wp-content/uploads/2013/06/hoodie_1_front.jpg 30.00 kg cm NPR 47 10 35.00 http://localhost/wordpress/wp-content/uploads/2013/06/hoodie_2_front.jpg kg cm NPR [/code] Путь в этом сгенерированном канале правильный. Когда я копирую и вставляю путь к изображению, он загружает изображения. Но на etsy API отправляется относительный путь. Пока я печатаю данные, содержащие путь к изображению, он возвращает примерно такой массив: [code] Array ( [image] => @/var/www/html/wordpress/wp-content/uploads/2013/06/hoodie_1_front.jpg;type=image/jpeg ) [/code] И когда я проверяю его в соответствующей папке, конкретное изображение существует. Итак, может ли кто-нибудь помочь мне, в чем здесь реальная проблема? Интересно то, что иногда с какого-то компьютера также отправляется изображение, и оно отправляется в магазин etsy. В чем здесь реальная проблема? Заранее спасибо. [b]ЕСЛИ вы хотите понять что-нибудь еще. Пожалуйста, прокомментируйте.[/b] Подробнее здесь: [url]https://stackoverflow.com/questions/48098248/not-uploading-images-in-etsy-shop-with-rss-feed-when-relative-path-is-given[/url]