Skip to content

Instantly share code, notes, and snippets.

@versedi
Last active December 21, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save versedi/4ad6598892c3c5500600 to your computer and use it in GitHub Desktop.
Save versedi/4ad6598892c3c5500600 to your computer and use it in GitHub Desktop.
Magento PHP Snippets
#Debug Layout
<?php Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles()); ?>
##Get Locale Code
<?php echo strtolower(Mage::getStoreConfig('general/country/default')); ?>
## Get Skin URL
<?php echo $this->getSkinUrl('images/logo.png'); ?>
##Is customer logged in
<?php
$_customerStatus = Mage::getSingleton('customer/session')->isLoggedIn();
if ($_customerStatus) {
}
?>
##Is logged in and customer group
<?php
$_customerStatus = Mage::getSingleton('customer/session')->isLoggedIn();
if ($_customerStatus) {
$_customerGroup = Mage::getSingleton('customer/session')->getCustomerGroupId();
if($_customerGroup==25) {
}
}
?>
##Calculate tax of shipping
<?php// echo $address->getQuote()->getStore()->convertPrice($_excl, false); ?>
<?php// echo $address->getQuote()->getStore()->convertPrice($_incl, false); ?>
<?php echo $excluding = (float)preg_replace('/\D/', '', $_excl)/100; ?>
<?php echo $including = (float)preg_replace('/\D/', '', $_incl)/100; ?>
<?php
$taxamount=$including-$excluding;
$taxPercentage = ($taxamount / 100) * $including;
$percent = $taxamount/$excluding;
echo $percent_friendly = number_format( $percent * 100, 2 ) . '%';
?>
##List all attributes with their IDs
<?php
$attrib_data = array(); $allAttributeCodes = array();
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')->getItems();
foreach ($attributes as $attribute){
$attrib_data[$attribute->getAttributeCode()] = $attribute->getData();
echo $allAttributeCodes[] = $attribute->getAttributeCode() . ';' . $attribute->getAttributeId() . '<br>';
}
?>
#Remove all customer addreses
<?php
public function removeAllAddreses($customer)
{
foreach($customer->getAddresses() as $address) {
$address->isDeleted(true);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment