by admin
If you use PHP Storm, then this will help you find something in the code such as short tags for PHP.
We had an issue that some of our server environments did not have php short tags enabled. We needed to get rid of them!
So, what you do is open up PHP Storm..then (mac version ) and hold down control, and hold down shift, then press F and in the Options check the Regular expression box. Then in the Text to Find enter:
<\?[^(php|xml)]
Kudos to Brian for this tip!
by admin
Have you ever just needed the customers company name or first name, or some custom customer attribute?
Well, I am tired of loading the entire customer object for just 2 or 3 things.
I have 2 custom customer attributes that I need, companyname and companywebsite
This would work for regular things like first name and last name as well!
Here is how:
Version 1:
// Get the customer data and set it on the object as companyname
$customer = Mage::getModel('customer/customer')
->getCollection()
->addFieldToFilter('entity_id', array('eq' => $customer_id))
->addAttributeToSelect('companyname')
->addAttributeToSelect('companywebsite')
->getItems();
$company_name = $customer[$customer_id]->getData('companyname');
$company_website = $customer[$customer_id]->getData('companywebsite');
Version #2 is slightly more easy to use
// Get the customer data and set it on the object as companyname
$customer = Mage::getModel('customer/customer')
->getCollection()
->addFieldToFilter('entity_id', array('eq' => $customer_id))
->addAttributeToSelect('companyname')
->addAttributeToSelect('companywebsite')
->getLastItem();
$company_name = $customer->getData('companyname');
$company_website = $customer->getData('companywebsite');
As you can see, version 1 needs to go through the array before you can have access to the method getData.
I would recommend version 2 as it stays with the typical way of doing things ( aka the magento way ).
by admin
If you have ever wondered how to figure out what that long string of letters and numbers are in a magento URL, here is how to do it.
Lets say that our URL is:
$string = 'www.whatever.com/customer/account/login/referer/aHR0cDovL2xvY2FsLmJsb29tMi5jb20vc2hvcA,,/';
Mage::helper('core')->urlDecode($string);
From what I can tell, it does the same thing as
base64_decode($string);
That will be decoded as
www.whatever.com/shop
Pretty fancy work there Magento! But I got you figured out.
by admin
If you are in a Magento Controller and you need to get a different block and its methods….here is how:
// This function would be in a controller called something like CustomerController.php
class Bloom_BeautyBio_CustomerController extends Mage_Core_Controller_Front_Action
{
public function viewAction()
{
/******** This is the secret sauce that gives you access to the class and its methods ******/
$viewingOthers = $this->getLayout()->createBlock('beautybio/beautybio')->viewingOtherMember();
if($viewingOthers)
{
$this->_redirect('beautybio/customer/view/#photos');
exit();
}
$this->loadLayout(array('default'));
$this->renderLayout();
}
}
by admin
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections
by admin
$query = “SELECT table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ‘database_name_goes_here’”;
$result = Mage::getSingleton(‘core/resource’) ->getConnection(‘core_read’)->fetchAll($query);
$total = 0;
for( $i = 0; $i {
$total += $result[$i]['table_rows'];
}
echo ‘Grand Total = ‘ . $total;
by admin
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-3-magento-controller-dispatch
Good tutorial
by admin
If your on the checkout/cart page, you can get the shipping totals:
$shipping_total = $this->getQuote()->getShippingAddress()->getShippingAmount();