1

I have this in my customer dashboard, so people can see and unsubscribe from product alerts:

<?PHP
$customer_id = Mage::getSingleton('customer/session')->getCustomer()->getId();
$customer_price_alerts = Mage::getModel('productalert/price')
         ->getCollection()
         ->addFieldToFilter('customer_id', $customer_id);
foreach ( $customer_price_alerts as $alert )
{
 echo $alert->getProductId();
}
    ?>

I can put some stuff in the echo to add unsubscribe link and more. The "more" is my problem. I can only echo the product ID... WHen i use echo $alert->getProductName(); or Url... it aint showing me stuff... just empty fields.

Can this be done? Else i need to know how to convert my product ID to a clickable link, so people can click and check what product is behind the ID (ugly... but better than nothing).

Thanks!

3 Answers 3

1
$customer_id = Mage::getSingleton('customer/session')->getCustomer()->getId();
$customer_price_alerts = Mage::getModel('productalert/price')
         ->getCollection()
         ->addFieldToFilter('customer_id', $customer_id);
foreach ( $customer_price_alerts as $alert )
{
 $productId = $alert->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
echo $product->getName();
}

Try it.

1
  • You are great :-)
    – Maarten
    Commented Dec 19, 2013 at 19:25
1
$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId);
$url = $product->getProductUrl();
$name = $product->getName();
1
  • i added your lines in my php snipet... i get "www.domain.com/catalog/product/view" when i use $product->getProductUrl() And when i use $product->getName() i get nothing :( ANd when i use links like this: domain.com/catalog/product/view/33910 i get a 404 error page. I use fancy url rewritten links ;)
    – Maarten
    Commented Dec 14, 2013 at 22:30
1

$productId = $alert->getProductId();

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

echo $product->getName();

1
  • this just shows errors: Fatal error: Call to a member function getProductId() on a non-object The error is in this: $productId = $alert->getProductId();
    – Maarten
    Commented Dec 14, 2013 at 23:40

Your Answer

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

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