Home

Monday, January 23, 2017

How to programmatically update short and long description using csv file for magento products ?

<?php
require_once '../app/Mage.php';
umask(0) ;
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$csv = new Varien_File_Csv();
$data = $csv->getData('sku_description.csv'); //path to csv
array_shift($data);

for($i=0;$i<count($data);$i++)
{
if($data[$i][0] != "")
{
$product_sku = $data[$i][0];
$short_description = $data[$i][1];
$long_description = $data[$i][2];

$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$product_sku);

if($product) {
$product->setShortDescription($short_description);
$product->setDescription($long_description);
$product->save();
echo "Updated product " . $productSku . "<br>";
}else
{
echo "Not - Updated product " . $productSku . "<br>";
}
}
}
?>

Please check image for CSV format.


Tuesday, January 10, 2017

How submit or insert data and files using JQuery Ajax ?

Step : 1 create Index.php file
----------------------------------------
<form id="data" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>FirstName</td>
<td><input type="text" name="firstName" value="" /></td>
</tr>
<tr>
<td>LastName</td>
<td><input type="text" name="lastName" value="" /></td>
</tr>
<tr>
<td>Attachment</td>
<td><input name="image" type="file" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
<div id="response"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$("form#data").submit(function(){
    var formData = new FormData($(this)[0]);
    $.ajax({
        url: "data.php",
        type: 'POST',
        data: formData,
        async: false,
        success: function (data) {
            //alert(data)
    $("#response").html(data);
        },
        cache: false,
        contentType: false,
        processData: false
    });
    return false;
});
</script>

Step : 2 create data.php file
----------------------------------------
<?php
echo "<pre>";
print_r($_FILES);
echo "<pre>";
print_r($_POST );
/// Put here your logic for insert and uploading code.
?>

Monday, January 2, 2017

How to change a product dropdown attribute to a multiselect in Magento using Database Query ?

UPDATE eav_attribute SET
entity_type_id = '10', // set here entity_type_id  from eav_attribute
attribute_model = NULL,
backend_model = 'eav/entity_attribute_backend_array',
backend_type = 'varchar',
backend_table = NULL,
frontend_model = NULL,
frontend_input = 'multiselect',
frontend_class = NULL
WHERE attribute_id = '1100'; // set here attribute_id  from eav_attribute


INSERT INTO catalog_product_entity_varchar ( entity_type_id, attribute_id, store_id, entity_id, value)
SELECT entity_type_id, attribute_id, store_id, entity_id, value
FROM catalog_product_entity_int
WHERE attribute_id = 1100; // set here attribute_id  from eav_attribute


DELETE FROM catalog_product_entity_int
WHERE entity_type_id = 10 and attribute_id = 1100; // set here attribute_id  from eav_attribute

How to add to cart configurable product in magento programmatically ?

<?php

include 'app/Mage.php';

Mage::app();

// Need for start the session

Mage::getSingleton('core/session', array('name' => 'frontend'));

try {

    $product_id = '389';

    $product = Mage::getModel('catalog/product')->load($product_id);

    $cart = Mage::getModel('checkout/cart');

    $cart->init();

    $params = array(

        'product' => $product_id,

        'super_attribute' => array(

            1102 => 351,              
        ),

        'qty' => 1,

    );

    $cart->addProduct($product, $params);

    $cart->save();

    Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

    Mage::getSingleton('core/session')->addSuccess('Product added successfully');

    header('Location: ' . 'index.php/checkout/cart/');

} catch (Exception $e) {

    echo $e->getMessage();

}

?>

rathoddhirendra.blogspot.com-Google pagerank and Worth