|
we need to set some attributes for each product on a daily base
our products are accessoires and parts for mobile phones
i.e. a universal screen protector can be used for a lot of phone models
also, new phone models are being introduced now and then
the mentioned screen protector could also be an accessoire for this new type
therefore we decided to generate the attribute connections daily and overwrite the existing values
All avaliable phone brands and models are already values in magento model/brand attributes.
$brandvals and $modelvals are being generated from our supplier data on a daily base
the below fixed values are just an example for debug purposes for 1 product only
newaspect_id is a custom text attribute containing supplier_id which has a reference to their brands/models
model and brand are custom multi select attributes
After updating a product only 255 chars of the string are being sent to the database resulting in 64 connected models instead of 1547!
I have tried to select all available models in magento backend and save it manually too.
this also will not go beyond 255 chars when viewing the product _origData:protected afterwards
The “Product succesfully saved” message appears though.
I use this function to update the product:
function update2ProductId($productId, $brandvals, $modelvals) { // returns 1 if saved, 2 if error, 99 product not exist, 0 no action
global $debug; $action = false; $errorlevel = 0;
if ($debug) { var_dump($productId); var_dump($prod->sku); var_dump($prod->brand); var_dump($prod->model); }
$prod = Mage::getModel('catalog/product')->loadByAttribute('newaspect_id', $productId); if (!$prod) { $errorlevel = 99; return $errorlevel; }
$prod->brand = $brandvals; $prod->model = $modelvals; if ($debug) { var_dump($prod); }
try { $prod->save(); $errorlevel = 1; // success } catch (Exception $ex) { //Handle the error $errorlevel = 2; // general error } if ($debug) { var_dump($errorlevel); } return $errorlevel; }
I’ve attached my full script since code snippet didn’t work for the total stringlengths.
please advice....
File Attachments
|