0

I am programatically updating some attributes of products through CSV import in "Advanced Dataflow Profiles". Of which, i have found the code to update quantity i.e. inventory information of a product.

Now there are some custom attributes which i need to change similarly. All these are string kind of attributes. But in dont get that in which database tables their values are stored. Can anyone modify the _updateAttribute() function so that i can update custom product attributes similarly??

I am using the following code:

<?php

class Mage_Catalog_Model_Convert_Adapter_Updateqty extends Mage_Catalog_Model_Convert_Adapter_Product {

public function saveRow( array $importData )
{ 
 function _getConnection($type = 'core_read'){
 return Mage::getSingleton('core/resource')->getConnection($type);
}
function _getTableName($tableName)
{
 return Mage::getSingleton('core/resource')->getTableName($tableName);
}
function _getAttributeId($attribute_code = 'price')
{
 $connection = _getConnection('core_read');
 $sql = "SELECT attribute_id FROM " . _getTableName('eav_attribute') . " WHERE entity_type_id = ? AND attribute_code = ?";
 $entity_type_id = _getEntityTypeId();
 return $connection->fetchOne($sql, array($entity_type_id, $attribute_code));
}
function _getEntityTypeId($entity_type_code = 'catalog_product')
{
 $connection = _getConnection('core_read');
$sql = "SELECT entity_type_id FROM " . _getTableName('eav_entity_type') . " WHERE entity_type_code = ?";
return $connection->fetchOne($sql, array($entity_type_code));
}
function _checkIfSkuExists($sku)
{
 $connection = _getConnection('core_read');
 $sql = "SELECT COUNT(*) AS count_no FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?";
 $count = $connection->fetchOne($sql, array($sku));
 if($count > 0)
 {
 return true;
 }
 else
 {
 return false;
 }
}
function _getIdFromSku($sku)
{
 $connection = _getConnection('core_read');
 $sql = "SELECT entity_id FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?";
 return $connection->fetchOne($sql, array($sku));
}
function _updateStocks($sku,$newQty)
{
 $connection = _getConnection('core_write');
 $productId = _getIdFromSku($sku);
 $attributeId = _getAttributeId();
 $sql = "UPDATE " . _getTableName('cataloginventory_stock_item') . " csi,
 " . _getTableName('cataloginventory_stock_status') . " css
 SET
 csi.qty = ?,
 csi.is_in_stock = ?,
 css.qty = ?,
 css.stock_status = ?
 WHERE
 csi.product_id = ?
 AND csi.product_id = css.product_id";
 $isInStock = $newQty > 0 ? 1 : 0;
 $stockStatus = $newQty > 0 ? 1 : 0;
 $connection->query($sql, array($newQty, $isInStock, $newQty, $stockStatus, $productId));
}
function _updateAttribute($sku,$newattri)
{
$connection = _getConnection('core_write');
 $productId = _getIdFromSku($sku);
$attributeId = _getAttributeId();
$sql = "UPDATE `catalog_product_flat_1` tbl
 SET
 tbl.materials_value = ?
 tbl."
}
set_time_limit(0);
ini_set('memory_limit','1024M');
$message = '';
$count = 1;
 if(_checkIfSkuExists($importData['sku']))
{
 try
 {
 _updateStocks($importData['sku'],$importData['qty']);
 $message .= $count . '> Success: Qty of Sku "' . $importData['sku'] . '" has been updated.';
 }
 catch(Exception $e)
 {
 $message .= $count .'> Error: while Upating Qty "' .$importData['qty'] . '" of Sku (' . $importData['sku'] . ') => '.$e->getMessage().'';
 }
 }
else
{
 $message .= $count .'> Error: Product with Sku "' .$importData['sku'] . '" does\'t exist.';
 }
 $count++;
echo $message;
} 

}

asked Dec 21, 2013 at 10:54
2

1 Answer 1

1

this is not a proper way to create files in Core Folders Helly.

you can create a custom module in magento and override the required Model. and if you want to update custom attribute at import time then you can import data using script.

It's Humble request to you Don't Change any Core Files Of Magento. If you want to customized Core Files Then Magento Provide us local Folder in Code Pool. you can just copy and paste that file and override the Functionality.

answered Dec 21, 2013 at 13:31
2
  • Thanks but I have kept this file in local code pool under : app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php. And not modified any core file! Commented Dec 21, 2013 at 13:54
  • :) Thats grate (y) Commented Dec 21, 2013 at 13:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.