Magento - Voorwaardes


De onderstaaande voorwaardes kunnen van pas komen bij het ontwikkelen van een shop. Zo kun je bijvoorbeeld controleren of je op de homepage bent of op een categoriepagina en een productpagina. Aan de hand hiervan kunnen er extra codes uitgevoerd worden.

CategorieŽn


Categorie

<?php
        if(Mage::registry('current_category')):
        endif;
?>


Categorie op basis van ID

<?php
        if(Mage::registry('current_category')->getId() == 3):
        endif;
?>


Controleer of categorie producten heeft

<?php
        $sale_count = Mage::registry('current_category')->getProductCount();
        if($sale_count > 0):
                echo 'Producten gevonden';
        else:
                echo 'Geen producten gevonden';
        endif;
?>


Controleer of specifieke categorie producten heeft

<?php
        $sale_count = Mage::getModel('catalog/category')->load(10)->getProductCount();
        if($sale_count > 0):
                echo 'Producten gevonden';
        else:
                echo 'Geen producten gevonden';
        endif;
?>


Controleer of categorie bestaat

<?php
        $category = Mage::getModel('catalog/category')->load(10);
        if($category->getId()):
        endif;
?>


Controleer of een categorie subcategorieŽn heeft

<?php
        if(Mage::registry('current_category')):
                $_category = Mage::registry('current_category');
                if(!$_category->hasChildren()):
                        echo 'Nee';
                else:
                        echo 'Ja';
                endif;
        endif;
?>


Anchor

<?php
        if(Mage::registry('current_category')):
                $_category = Mage::registry('current_category');
                $anchor = $_category->getIsAnchor();
                if($anchor == '1'):
                endif;
        endif;
?>

Producten


Product

<?php
        if(Mage::registry('current_product')):
        endif;
?>


Product ID

<?php
        if($_product->getId() == '5'):
        endif;
?>


Gegroepeerd product

<?php
        $productType = $_product->getTypeId();
        if($productType == 'grouped'):
        endif;
?>


Configureerbaar product

<?php
        $productType = $_product->getTypeId();
        if($productType == 'configurable'):
        endif;
?>


Simpel product

<?php
        $productType = $_product->getTypeId();
        if($productType == 'simple'):
        endif;
?>


Gebundeld product

<?php
        $productType = $_product->getTypeId();
        if($productType == 'bundle'):
        endif;
?>


Voorraad

<?php
        $quantity = intval(Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty());
        if($quantity == '' || $quantity <= '0'):
                echo $this->__('Dit product is momenteel niet beschikbaar');
        endif;
?>


Attribuut productpagina

<?php
        if($_product->getModel()):
        endif;
?>


Attributenset productpagina

<?php
        if($_product->getAttributeSetId() == '5'):
        endif;
?>


Special Price

<?php
        $special = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
        $specialfromdate = strtotime(Mage::getModel('catalog/product')->load($_product->getId())->getSpecialFromDate());
        $specialtodate = strtotime(Mage::getModel('catalog/product')->load($_product->getId())->getSpecialToDate());
        $today = time();
        if(!$special == ''):
                if($today >= $specialfromdate && $today <= $specialtodate || $today >= $specialfromdate && $specialtodate == ''):
                endif;
        endif;
?>


Controleren of er Upsell producten zijn ingesteld

<?php
        if(strlen($this->getChildHtml('upsell_products')) > 0):
        endif;
?>


Kan verkocht worden

<?php
        if($_product->isSaleable()):
        endif;
?>

Pagina's Magento


Pagina

<?php
        if($this->getRequest()->getModuleName() == 'cms'):
        endif;
?>


Homepage

<?php
        if(Mage::getSingleton('cms/page')->getIdentifier() == 'home'):
        endif;
?>


Pagina ID

<?php
        $pageId = Mage::getBlockSingleton('cms/page')->getPage()->getId();
        if($pageId == '2'):
        endif;
?>


Pagina Identifier

<?php
        $pageId = Mage::getBlockSingleton('cms/page')->getPage()->getIdentifier();
        if($pageId == 'disclaimer'):
        endif;
?>


404 pagina

<?php
        $errorCheck = Mage::app()->getRequest()->getActionName();
        if($errorCheck == 'noRoute'):
        endif;
?>

Gebruikers


Ingelogd

<?php
        if(Mage::getSingleton('customer/session')->isLoggedIn()):
                echo '<a href="/customer/account/logout/">Uitloggen</a>';
        else:
                echo '<a href="/customer/account/login/">Inloggen</a>';
        endif;
?>


Groep ID

<?php
        $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
        if($groupId == '2'):
        endif;
?>


Groep code

<?php
        $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
        $groupCode = Mage::getSingleton('customer/group')->load($groupId)->getData('customer_group_code');
        if($groupCode == 'General'):
        endif;
?>

Overig


Module

<?php
        $check = $this->getRequest()->getModuleName();
        if($check == 'catalog'):
        endif;
?>


Controller

<?php
        $check = $this->getRequest()->getControllerName();
        if($check == 'product'):
        endif;
?>


Route

<?php
        $check = $this->getRequest()->getRouteName();
        if($check == 'catalog'):
        endif;
?>


Taal / Winkelcode

<?php
        $storeCode = Mage::app()->getStore()->getCode();
        if($storeCode == "default"):
                echo "EN";
        elseif($storeCode == "nl"):
                echo "NL";
        endif;
?>


Statisch blok

<?php
        $isactive = Mage::getModel('cms/block')->load('block_identifier')->getIsActive();
        if($isactive == '1'):
        endif;
?>