3

Once Registered customers click on "Create Product" button present in product view page, we are creating new product in database. now we need to

1)Save those newly created product details in custom Table : my_designs

we are successfuly doing with help of this code :

$data = array('title'=>fav1_id,'product_id'=>$product->getId(),'customer_id'=>
 Mage::getSingleton('customer/session')->getId());
$model = Mage::getModel('example/mydesign')->setData($data);

enter image description here

2)display those products in My Designs section in Customer's My Account by fetching values from my_designs table.

I am using module & I am trying below code to display those products under My Designs section.

Issue : in customer 1's Dashboard only Products created by customer 1 should display, but now its displaying all customer's Products.

<?php $collections = $this->getCollection(); ?>
<?php foreach ($collections as $key => $product) {
    $_product = Mage::getModel('catalog/product')->load($product->getProductId());        
    echo $product->getId().'<br />';
    echo $_product->getName().'<br />';

}
?>

full module : http://www.filedropper.com/amasty-module1

  • i will give 100 bounty points if it worked for me..... – Baby in Magento Mar 13 '17 at 8:00
  • Did you save product in my_design table once click Create Product. I mean it saved Database – Magento 2 Mar 13 '17 at 8:30
  • You want to create new product or in view page that paroduct to save my_design table – Magento 2 Mar 13 '17 at 9:28
  • @Kothari I am creating new product once click on button & now i need to save that product to my_design table, so that i can display under My designs under My account – Baby in Magento Mar 13 '17 at 9:33
  • 1
    Murtuza Zabuawala given you the best sollution. You can work according to his answer. – Mujahidh Mar 14 '17 at 4:42
3
+50

Below code will get you products for a customer.
Update your file app\code\local\Amasty\Example\Block\List.php::__construct()

public function __construct() {
    parent::__construct();
    $idc = Mage::getSingleton('customer/session')->getId();
    $customerSavedProductArray = array();
    $customerSavedProductArray = Mage::getModel('example/mydesign')->getCollection()->addFieldToFilter('customer_id',$idc)->getColumnValues("product_id");
    $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('entity_id', array("in"=>$customerSavedProductArray));
    $collection->load();
    $this->setCollection($collection);
}

Now update file app\design\frontend\rwd\default\template\example\example.phtml

<?php $collections = $this->getCollection(); ?>
<?php foreach ($collections as $key => $product) {
    //$_product = Mage::getModel('catalog/product')->load($product->getProductId());    
    //echo $product->getProductUrl().'<br />';
    echo $product->getId().'<br />';
    echo $product->getName().'<br />';
    //echo $_product->getImage().'<br />';
    //echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getImage() ).'<br />'; 
    //echo $_product->getFinalPrice();'<br />';
}
?>
<!--
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
                                     src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image'); ?>"
                                     alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>

-->
  • Thanks a lot for your valuable time...... it worked fine..... – Baby in Magento Mar 15 '17 at 13:17
1

Well you can use different attribute set for that kind of product ,

and one of that attribute contains the customer_id and filter product collection using that customer_id attribute basis

and show them in users dashboard.

For filtering product you can use below code

$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('customer_id',array('eq'=>$customer_id));
foreach($collection as $product){
   echo $product->getId();
}
  • yes i created different attribute set as custom_Design & created new attribue customer_id for that attribute set, please help me for filter product collection using that customer_id attribute basis – Baby in Magento Mar 13 '17 at 9:33
  • @BabyinMagento provide me the link – Murtuza Zabuawala Mar 14 '17 at 5:49
  • please check link , you can see create button next to add tocart and save design – Baby in Magento Mar 14 '17 at 5:50
  • Provide me question link – Murtuza Zabuawala Mar 14 '17 at 5:53
  • I mentioned in this question only that i need to display products under My Designs section.... i need to save in DB, than only i can display in My Designs , please help me to save in Db – Baby in Magento Mar 14 '17 at 5:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.