lets take a look at some code real quick and see if we can collectively diagnose the error residing within this code.
<span>
<?php
$_category = array_unique($_category);
foreach ($_category as $cat) {
var_dump($cat);
$category = $collection->load($cat);
var_dump($category->getName());
if($category->getName()) {
echo '<a href="' . $category->getUrl() . '">More <strong>Of the ' . $category->getName() . '</strong></a>';
echo 'test'
}
unset($category);
}
?>
</span>
The above code is used to display category URLs along within their respective names to the user. Easy enough, right? However -- many of our products are shared between sites and as a result some category getNames do not resolve in one of our much smaller stores. This isn't an issue anywhere else, as far as I can tell, but here. When a the if($category->getName)
boolean is found to be true for a category, but the next one is found to be false it will repeatedly output the previously echo'd statement.
So it will look something like this:
input:
$_category={123,124,125,126} // only 124 is resolving to a name.
output:
string(3)"123"NULLstring(3)"124"string(4)"same"
More of the same
teststring(3)"125"string(4)"same"
More of the same
teststring(3)"126"string(4)"same"
More of the same
test
After further testing it seems that the $category
variable isn't changing after each iteration of the for look. I've even tried to unset($category)
after every iteration with no success.