Open matiaso opened 9 years ago
Good question. I will tag @willy-ahva since he wrote that code and I'm not sure what it would break if we removed that bit.
Hi guys,
I never update this code but, if this line nullify empty values, try to put (int) 0 in your data. If a value is needed, an empty value will be exactly the same than a NULL and will cause an error. Code is ok, pls update your data ;) It works for me.
Regards, Willy
I use the API through a Soap component in Talend, when I send a value like:
This is nulled by the trim in the code and therefore causes an error when inserted into the db. Le 11 févr. 2015 18:46, "willy-ahva" notifications@github.com a écrit :
Hi guys,
I never update this code but, if this line nullify empty values, try to put (int) 0 in your data. If a value is needed, an empty value will be exactly the same than a NULL and will cause an error. Code is ok, pls update your data ;) It works for me.
Regards, Willy
— Reply to this email directly or view it on GitHub https://github.com/danslo/ApiImport/issues/28#issuecomment-73927526.
Are you sure 0 is passed in the trim ? I ask it because trim(0) returns 0 so I don't really understand. Another fix could be to send "0" instead of 0, it should work.
Regards, Willy
Ok, but !trim(0) is true and then the value is set to NULL.
If I set the value to "0" it causes an SQL error as well.
On Thu, Feb 12, 2015 at 9:56 AM, willy-ahva notifications@github.com wrote:
Are you sure 0 is passed in the trim ? I ask it because trim(0) returns 0 so I don't really understand. Another fix could be to send "0" instead of 0, it should work.
Regards, Willy
— Reply to this email directly or view it on GitHub https://github.com/danslo/ApiImport/issues/28#issuecomment-74037383.
Ok, I see. You can try to check if (!trim($value) && !is_numeric($value)). If it works pls PR it ;)
The following should then also work, and should be a bit cleaner:
$value = trim((string)$object->value);
if (strlen($value)) {
$return[$i][$object->key] = $value;
}
But in this case, a 0 will be cast in "0", and it will result as an SQL error, no ?
Just checked this.
<?php
require_once 'app/Mage.php';
Mage::app('admin');
$products = Mage::helper('api_import/test')->generateRandomSimpleProduct(1);
$products[1]['_media_attribute_id'] = Mage::getModel('eav/entity_attribute')
->load('media_gallery', 'attribute_code')
->getAttributeId();
$products[1]['_media_image'] = '/a.png';
$products[1]['_media_is_disabled'] = '0'; // Notice that it's a string.
$products[1]['_media_position'] = '0';
try {
Mage::getModel('api_import/import_api')->importEntities($products, 'catalog_product');
} catch (Exception $e) {
printf("%s: %s\n", $e->getMessage(), $e->getCustomMessage());
}
Works fine for me. No exception thrown in _saveMediaGallery
.
So it's what I said previously @danslo. Replace 0 by "0" works, and we shouldn't update the code, no ?
I think that should work, so that's why these are probably 2 issues:
NULL
, instead of not setting them at all."0"
not work for @aphroz .I think it is related with the fact that I use a Java component to send the data as XML to the API.
If I send something like
Hello,
I use Talend to import 1'000 products per API call and I encountered some issues when I tried to import products gallery images.
The code in ApiImport/code/Model/Import/Api/V2.php line 49 set the value of _media_is_disabled to NULL and it causes an SQL error because this value cannot be NULL.
Why is it needed to remove empty values?