Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1850 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Magento 1.9 Fil d'ariane

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Magento 1.9 Fil d'ariane

n°2280705
runa
Posté le 03-05-2016 à 15:58:49  profilanswer
 

Bonjour à tous,
 
Pour un projet je dois mets en place sur magento un fil d'ariane, alors j'ai réussi à faire pas mal de chose.
 
Déjà j'ai trouvé un morceau de code permettant de récupérer les catégories du produit, donc c'est bien !!
Par contre dès que je dépasse 1 catégories, je me retrouve qu'avec Accueil et produit
 
Ce que j'ai actuellement est sous la forme
 
1 catégorie Accueil\Catégorie1\Produit
2 catégories Acceuil\Produit
 
Ce que je cherche c'est sa
 
1 catégorie Accueil\Catégorie1\Produit
2 à X catégorie Accueil\Catégorie1\Catégorie2\...\Produit
 
Voilà code trouvé et modifié
 
<?php
$category = null;
if ($product = Mage::registry('current_product')) {
    $categories = $product->getCategoryCollection()->load();
     
    if($categories) {
        foreach ($categories as $category)
        {
            if($category) {
                $category = Mage::getModel('catalog/category')->load($category->getId());
                break;
            }
        }
    }
    $lastCrumbName = $product->getName();
    $lastCategoryAdjust = 0;
}
else {
    if($category = Mage::registry('current_category')) {
        $lastCrumbName = $category->getName();
    }
    $lastCategoryAdjust = 1;
}
 
if($category) {
    if($path = $category->getPath()) {
        $path = explode('/', $path);
        $crumbs = array('home' => array('label' => 'Accueil',
                        'title' => 'Accueil',
                        'link' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB),
                        'first' => true,
                        'last' => false
        ));
        for($i = 2; $i < count($path) - $lastCategoryAdjust; $i++) {
            $cur_category = Mage::getModel('catalog/category')->load($path[$i]);
            if($cur_category && $cur_category->getIsActive()) {
                $crumbs['category' . $path[$i]] = array('label' =>  $cur_category->getName(),
                                  'title' => $cur_category->getName(),
                                  'link' => $cur_category->getUrl(),
                                  'first' => false,
                                  'last' => false
                );
            }
        }
        $crumbs['current'] = array('label' => $lastCrumbName,
                       'title' => '',
                       'link' => '',
                       'first' => false,
                       'last' => true
        );
    }
}
?>  
 
Et voilà le code pour l'affichage
 
<?php $i = 1;
if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
    <ul itemscope itemtype="http://schema.org/BreadcrumbList">
        <?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
            <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" class="<?php echo $_crumbName ?>">
            <?php if($_crumbInfo['link']): ?>
                <a itemprop="item" href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><i itemprop="name"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></i></a>
            <?php elseif($_crumbInfo['last']): ?>
  <a itemprop="item" class="no-display" href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
                <strong itemprop="name"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
            <?php else: ?>
  <a itemprop="item" class="no-display" href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
                <?php echo $this->htmlEscape($_crumbInfo['label']) ?>
            <?php endif; ?>
   <meta itemprop="position" content="<?php echo $i ?>" />
   <?php $i++; ?>
            <?php if(!$_crumbInfo['last']): ?>
                <span>/ </span>
            <?php endif; ?>
     
            </li>
        <?php endforeach; ?>
    </ul>
</div>
<?php endif; ?>
 
Je suis sûr que c'est un problème de boucle ou quelque chose du genre mais j'arrive pas à savoir ou >< Merci de votre aide !

mood
Publicité
Posté le 03-05-2016 à 15:58:49  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Magento 1.9 Fil d'ariane

 

Sujets relatifs
Magento Reindex CONSTRAINTMagento ou Prestashop?
Magento et OVHMagento ou prestashop
configurer PHP pour intaller Magento[Vb.net] Fil d'ariane
[Résolu] Fil d'Ariane PHP/MySQL sur système d'include 
Plus de sujets relatifs à : Magento 1.9 Fil d'ariane


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR