Sometimes, when looking through your Magento log files, you might stumble upon the “Cannot send headers; headers already sent in …” message. One possible reason for that could be a space or a newline behind a closing PHP tag (?>).…
Adding a static block to a CMS page (Magento 1)
Use the below code to add a Magento block to your CMS page.
|
1 |
{{block type="cms/block" block_id="block_id"}} |
Unlock customer programmatically (Magento 1)
Use the below code to unlock a customer programmatically.
|
1 |
$customer->setFailedLogins(0)->setLastFailedLogin(0)->save(); |
Creating order including custom options programmatically (Magento 1)
Using the following code, you can create an order including custom options programmatically.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId()); $quote->setCustomerEmail($mail); $product = Mage::getModel('catalog/product')->load($productId); $buyInfo = array( 'qty' => 1, 'options' => array($optionId => $optionValue) ); $quote->addProduct($product, new Varien_Object($buyInfo)); $addressData = array( 'firstname' => $firstName, 'lastname' => $lastName, 'street' => $street, 'city' => $city, 'postcode' => $postCode, 'telephone' => '-', 'country_id' => $country, 'region_id' => $regionId, ); $billingAddress = $quote->getBillingAddress()->addData($addressData); $shippingAddress = $quote->getShippingAddress()->addData($addressData); $shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('flatrate_flatrate') ->setPaymentMethod('bankpayment'); $quote->getPayment()->importData(array('method' => 'bankpayment')); $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); // ... |
Getting a list of all countries (Magento 1)
Use the code below to get a list of all countries. It can be used to create a country dropdown list for example.
|
1 |
$countryList = Mage::getModel('directory/country')->getResourceCollection()->loadByStore()->toOptionArray(true); |
Loading a model without using IDs (Magento 1)
Sometimes there is no id available for loading a model. If thats the case, the following code might help out. It loads a collection by an attribute like name or sku.
|
1 |
$collectionData = Mage::getModel('modelname')->getCollection()->addFieldToFilter('attribute', 'attribute value'); |
Afterwards, it is possible to iterate over the…
Removing block from cache (Magento 1)
To remove a certain block from the Magento cache, use the below code.
|
1 2 3 |
<reference name="name.of.the.block"> <action method="setCacheLifetime"><s>null</s></action> </reference> |
Getting the status of every product in the database using MySQL (Magento 1)
The following MySQL query returns the status of every product in the Magento database.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
SELECT cpe.sku, q.product_status FROM catalog_product_entity cpe JOIN (SELECT entity_id AS product_id, value AS product_status FROM catalog_product_entity_int WHERE entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product') AND attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'status' AND entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product'))) q ON cpe.entity_id = q.product_id; |
Status 1: active Status 2: not active
Change column count of category page in admin area (backend) (Magento 1)
Open the category in the admin area (backend) and add the following xml to the layout update section.
|
1 2 3 |
<reference name="product_list"> <action method="setColumnCount"><count>4</count></action> </reference> |
Suppress warning when searching on https secured pages (Magento 1)
Searching for something while being on a https secured page opens a warning dialog. Thats annoying for the visitor of your page. To fix that problem, open a suitable module or create a new one and add the following xml…