Skip to content

Instantly share code, notes, and snippets.

@herveguetin
herveguetin / flat_source_table_select_varchar.php
Last active August 29, 2015 13:58
Save an attribute with a select input type with values that are not of "int" type and create correct column type in flat catalog tables (in Magento)
<?php
class Your_Module_Model_Catalog_Attribute_Source_Product_[Attribute] extends Mage_Eav_Model_Entity_Attribute_Source_Table
{
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = array(
'option_1' => array('value' => 'value_1', 'label' => Mage::helper('adminhtml')->__('-- Not Selected --')),
'option_2' => array('value' => 'value_2', 'label' => 'Label 2'),
@herveguetin
herveguetin / clean_catalogsearch.sql
Last active August 29, 2015 13:59 — forked from leek/_Magento1_DeleteTestData.md
Clean Magento Database
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `catalogsearch_fulltext`;
TRUNCATE `catalogsearch_query`;
TRUNCATE `catalogsearch_result`;
--
-- Enterprise Edition
--
@herveguetin
herveguetin / checkout_total_discount_no_code.phtml
Last active August 29, 2015 14:00
Remove coupon code in parenthesis from discount total title in Magento
<?php
$title = ($this->getTotal()->getCode() == 'discount') ? preg_replace('@\(.*?\)@', '', $this->getTotal()->getTitle()) : $this->getTotal()->getTitle();
?>
@herveguetin
herveguetin / Amasty_Shopby_Helper_Attributes.php
Last active August 29, 2015 14:00
Bugfix - Make sure to sort filter options by sort order set in Magento attribute option edit
<?php
/**
* @return array
*/
public function getAllFilterableOptionsAsHash()
{
if (is_null($this->_optionsHash)) {
$hash = array();
$attributes = $this->getFilterableAttributes();
@herveguetin
herveguetin / translation_var_order.csv
Created April 27, 2014 04:12
Manage different var positions in Magento translations
%1$s %2$s private sales Ventes privées %2$s %1$s
@herveguetin
herveguetin / product_entity_type_id.php
Created May 20, 2014 16:51
Retrieve product entity type ID in Magento
<?php
Mage::getModel('eav/entity_type')->loadByCode(Mage_Catalog_Model_Product::ENTITY)->getEntityTypeId();
@herveguetin
herveguetin / first_product_category.php
Created May 20, 2014 17:25
Retrieve first active category of product in Magento
<?php
// $product must be an instance of Mage_Catalog_Model_Product
$productCategoryIds = $product->getCategoryIds();
$productCategory = Mage::getModel('catalog/category')->getCollection()
->addAttributeToFilter('is_active', true)
->addAttributeToFilter('entity_id', array('in' => $productCategoryIds))
->setPageSize(1)
->getFirstItem();
@herveguetin
herveguetin / catalog_category_attribute_price.php
Created May 26, 2014 22:04
Create a new price attribute for category in Magento
<?php
$catalogInstaller = new Mage_Catalog_Model_Resource_Setup('core_setup');
$catalogInstaller->addAttribute('catalog_category', 'myattribute_code', array(
'type' => 'decimal',
'label' => Mage::helper('myHelper')->__('Price From'),
'input' => 'text',
'input_renderer' => 'adminhtml/catalog_product_helper_form_price',
'required' => false,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'sort_order' => 9999,
@herveguetin
herveguetin / store_date_interval.php
Created May 26, 2014 22:20
Check if current Magento store date is in given range
<?php
Mage::app()->getLocale()->isStoreDateInInterval(null, $myfromDate, $myToDate);
@herveguetin
herveguetin / test_order_success_page.md
Created May 26, 2014 22:30
Test Magento order success page

In Mage_Checkout_OnepageController, temporarely comment out $session->clear();