In catalog_product_flat_1 table, we created a custom column custom_uid & saving customer ids

Assume below image is the catalog_product_flat_1 table. You can see the columns contain Product name and customer id.

enter image description here

We are trying to fetch Product information from catalog_product_flat_1 table & trying to display in My account section. but its not fetching.

Means in customer with id 101's account, we are trying to display Product 1 & product2 . & in in customer id 102's account, we are trying to display Product 3

app/code/local/Amasty/Example/Block - List.php

class Amasty_Example_Block_List extends Mage_Core_Block_Template
 public function __construct() {
        $idc = Mage::getSingleton('customer/session')->getId();
     $customerSavedProductArray = array();
     $customerSavedProductArray = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('custom_uid',$idc)->getColumnValues("name");
//  $customerSavedProductArray = Mage::getResourceModel('catalog/product_collection')->addFieldToFilter('custom_uid',$idc)->getColumnValues("name");
    $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('entity_id', array("in"=>$customerSavedProductArray));



<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php $collections = $this->getCollection(); ?>
<?php $_product = $this->getProduct(); ?>

<?php foreach ($collections as $key => $product) {

    echo $product->getName().' <br><br>';
    echo $product->getId().'<br><br>';  
    $_product = Mage::getModel('catalog/product')->load($product->getId());  



In config.xml, i used table name : catalog_product_flat_1

<?xml version="1.0"?>




First of all, you are doing it wrong.
You should never manually add columns to any catalog_product_flat_* table.
These tables is just an index of the active products for each store view.
When you rebuild the indexes, these tables are regenerated. If you add a column to it you will lose it on the next reindex.
You should add a product attribute called custom_uid with the flag used in product listing set to yes.
Then reindex everything.
After that you can get the products collection for a specific customer like this:

$customerId = 8; //your customer id here - it can come from session
$collection = Mage::getModel('catalog/product')->
    ->addAttributeToSelect('*') // instead of * you can put an array with only the attributes you need
    ->getCollection()->addAttributeToFilter('custom_uid', $customerId);

Then you can simply loop through the collection and do something with each product, but don't use load in the foreach loop.

foreach ($collection as $product) {
    //do something with $product

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy