0

I have a foreach loop that I am running over a Magento collection so I can run pull in the info for multiple patients (it's a pharmacy). However, after each iteration of the foreach loop, it returns the values for the first value in the collection every time. If I manually pass the values for what should be values 2, 3, 4, etc in the collection, it does work properly.

Here is my function.

<?php foreach($this->getPatients() as $pat): ?>
    <?php //Pass patient ID to the collection so it can filter by patient ID ?>
    <?php $autoreorderCollection = null; ?>
    <?php $patientId = $pat->getId(); ?>
    <?php $autoreorderCollection = $this->getCollection($patientId); ?>
    <?php echo $autoreorderCollection->getSize(); ?>
<?php endforeach ?>

It returns the value for the first entity in the collection every time the foreach is iterated through. If I pass the value for the second entity manually, collection for that entity is returned. That tells me it's an issue with the foreach loop and not with the function. What am I doing wrong?

1 Answer 1

0

Instead of using $autoreorderCollection = $this->getCollection($patientId);

You have to load this patient with new object. Then you will get the new patient value.

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.