The following snippet returns the current date and time.
|
1 |
$dateAndTime = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())); |
The following snippet returns the current date and time.
|
1 |
$dateAndTime = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())); |
Sometimes, when opening a Magento product page, the following error is shown: Parse error: syntax error, unexpected ‘endif’ (T_ENDIF) in … The problem here is not with the Magento code itself. Its a problem with the Apache server configuration. To…
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 (?>).…
Use the below code to add a Magento block to your CMS page.
|
1 |
{{block type="cms/block" block_id="block_id"}} |
Use the below code to unlock a customer programmatically.
|
1 |
$customer->setFailedLogins(0)->setLastFailedLogin(0)->save(); |
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(); // ... |
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); |
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…
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> |
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