7

I'm implementing Prev/Next button on Product view page following Inchoo's Blog. It's working fine with Default Magento Theme but in My theme there is an issue with getting product position from Category.

In Product's view.phtml I've added code

<?php $_prev = $this->helper('retailon_productprevnext')->getPreviousProduct(); ?>
<?php $_next = $this->helper('retailon_productprevnext')->getNextProduct(); ?>
<?php if($_prev): ?><a class="product-prev" href="<?php echo $_prev;?>"><?php echo $this->__('< Previous')?></a><?php endif; ?>
<?php if($_next): ?><a class="product-next" href="<?php echo $_next;?>"><?php echo $this->__('Next >')?></a><?php endif; ?>

The Code for previous product in my Helper is like this:

     public function getPreviousProduct()
        {
            $prodId = Mage::registry('current_product')->getId();

            $catArray = Mage::registry('current_category');

            if($catArray){
var_dump($catArray); 
                $catArray = $catArray->getProductsPosition();

var_dump($catArray); 
/// Remaining code to return previous product

First dump is returning category array info, while the second one is not dumping any value.

Is there any other way using which I can get product position from category array instead of using $catArray = $catArray->getProductsPosition(); ?

0

1 Answer 1

1

If the first dump returns an array, I would be astonished if the second dump actually gets executed.

$catArray = $catArray->getProductsPosition();

...must give you a fatal error, because you are calling a function on a non-object. My guess: the products position data is not loaded in the current-category-registry. So what I'd try is:

$category = Mage::getModel('catalog/category')->load($catArray['entity_id']);
$positions = $category->getProductsPosition();
Zend_Debug::dump($positions);
1
  • I think he may be miss-interpreting the var_dump of the OBJECT as an array, due to how var_dump is outputting the result.
    – ProxiBlue
    Commented Apr 1, 2016 at 2:12

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.