Follow by Email

Thursday, May 22, 2014

Magento Custom single table extension

Suppose we have a table call "customer_product_like" having field (entity_id, store_id, customer_id, )

Now i want to insert data in this table then the code will be
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
$fields = array();
$fields['status']= $postData['like'];
$fields['store_id']= Mage::app()->getStore()->getId();
$fields['product_id']= $postData['prodId'];
$fields['customer_id']= $customerId;
$connection->insert('customer_product_like', $fields);

for update
$where = "entity_id = '".$customerProductLikeId."'";
$connection->update('customer_product_like', $fields, $where);

For select
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
 $select = $connection->select()
                    ->from('customer_product_like', array('*'))
                    ->where("product_id = '".$prodId."' AND customer_id = '".$customerId."' AND store_id = '".$storeId."'");
$result = $connection->fetchRow($select);   OR   $result = $connection->fetchAll($select);

No comments:

Post a Comment