we are importing product from outside of magento.we create an mappings for all attributes as target attributes and magento attributes.we have categorys as Abc/Cde/efg.Here is my category mapping code
foreach($Categories as $Category)
{
$categories = explode('/', $Category);
if(count($categories) > 0)
{
$level = 2;
$parentId = 2;
foreach($categories as $category) {
$categoryCollection = $categoryModel->getCollection();
$categoryCollection->addAttributeToFilter('name', array('eq' => $category));
$categoryCollection->addFieldToFilter('level', array('eq' => $level));
$categoryCollection->addFieldToFilter('parent_id', array('eq' => $parentId));
if($categoryCollection->getSize() > 0)
{
$return[$mapping->getAttribute()][] = $parentId = $categoryCollection->getFirstItem()->getId();
}
$level++;
}
}
}
i will loop into categories and assign it level wise. Now i need to change the code as i need to assign to the last category only i.e abc/cde/fdf categorys are there i need to assign only to fdf category only.how can i change my code to assign to last category only.