-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot import _media_is_disabled value if 0 #28
Comments
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. Regards, |
I use the API through a Soap component in Talend, when I send a value like: _media_is_disabled This is nulled by the trim in the code and therefore causes an error when
|
Are you sure 0 is passed in the trim ? I ask it because trim(0) returns 0 so I don't really understand. Regards, |
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 [email protected]
|
Ok, I see. You can try to check if (!trim($value) && !is_numeric($value)). |
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 |
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:
|
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 "0" the data received will be '"0"' and cause an exception when inserted in SQL. |
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?
The text was updated successfully, but these errors were encountered: