Magento: Invalid transactional email code: xy

28. September 2011 at 18:19

Taucht der Fehler z.b. bei der Registrierung oder finalen Absendung einer Bestellung auf, so ist die Ursache oft dass ein E-Mail-Template gelöscht wurde (id xy, für xy steht meist die template-id welche in der Datenbank angegeben wurde).

Die Lösung ist eifnach: Unter “System->Configuration->Sales Emails” im Admin-Backend einfach das Template wieder anlegen & speichern, welches vermisst wird.

Magento: delete an system attribute

13. September 2011 at 18:56

To delete a system attribute in Magento, you must first have to make it user defined.

– Go to phpmyadmin
– Go to your magento installation database
– Go to eav_attribute table
– Browse table with attribute_code ‘YOUR_ATTRIBUTE_CODE’ OR browse the table with the attribute_id of your    attribute (‘your attribute’ means the attribute which you want to remove as system attribute)
– Edit the table row of your attribute
– Find the field „is_user_defined“ and set the value to 1
– save the attribute

 

Now your attribute no longer remains System Attribute
Now you can delete it from Attribute manager

Magento: Mail versenden

8. September 2011 at 16:35

send email in magento (php-code) :

$template_var_array = array(
'var_1' => 'value 1',
'var_2' => 'value 2'
);
$sender = array('name' => 'name', 'email' => 'email@adresse.com');
$translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false);
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate->setDesignConfig(array('area' => 'backend'))
->sendTransactional(
Mage::getStoreConfig('core/email_template'),
Mage::getStoreConfig('general'), // alternate $sender
Mage::getStoreConfig('general'), // absender
null,
$template_var_array;
}
}

Magento: Parent Role id ‚G4‘ does not exist (or other ids)

2. September 2011 at 11:35

Magento reads the rows from the database table admin_role in the wrong“ order. That is it reads the user entry before the parent group (the role) is loaded. This happends because the user rows has a tree_level = 1, when they should have tree_level = 2 or more.

Solution:

To fix a broken admin-interface, run the following query in the magento database:
UPDATE admin_role SET tree_level = 2 WHERE role_type = “U”;

To prevent the error from happening again:
Open up the file app/code/core/Mage/Admin/Model/Mysql4/User.php

On line 162 (or close to that line) you find a row that says:
‘tree_level’ => $row[’tree_level’] + 1,

change this line to:
‘tree_level’ => $row[’tree_level’] + 2,

Magento: Page Cache anpassen

23. August 2011 at 11:22

Das Caching könnt ihr in Magento wie folgt beeinflussen:

protected function _construct()
{
$this->addData(array(
'cache_lifetime'    => 900,
'cache_tags'        => array(Mage_Catalog_Model_Product::CACHE_TAG),
'cache_key'            => $this->getCacheKey()
));
}
public function getCacheKey()
{
return $this->getRequest()->getRequestUri().$this->getCacheCurrencyCode();
}
//retreive current currency code
public function getCacheCurrencyCode()
{
return Mage::app()->getStore()->getCurrentCurrencyCode();
}

De-Aktivieren könnt ihr das Caching wie folgt:

protected function _construct()
{
$this->addData(array(
'cache_lifetime'    => null,
'cache_tags'        => array(Mage_Catalog_Model_Product::CACHE_TAG)
));
}

Magento: system.xml um weitere Felder erweitern – Daten-Typen

19. Juli 2011 at 15:44

Folgende Typen / Möglichkeiten gibt es in Magento um im Backend Datums-Typen Anzuzeigen (weg über system.xml):

<use_calendar translate="label">
<label>Use JavaScript Calendar</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</use_calendar>
<date_fields_order translate="label">
<label>Date Fields Order</label>
<frontend_type>select</frontend_type>
<frontend_model>adminhtml/catalog_form_renderer_config_dateFieldsOrder</frontend_model>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</date_fields_order>
<time_format translate="label">
<label>Time Format</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_catalog_timeFormat</source_model>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</time_format>
<year_range translate="label comment">
<label>Year Range</label>
<comment>Use four-digit year format.</comment>
<frontend_type>text</frontend_type>
<frontend_model>adminhtml/catalog_form_renderer_config_yearRange</frontend_model>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</year_range>

Magento: Category & Store Group & Store View über Setup Script anlegen

29. Juni 2011 at 11:12

magento ecommerce logo

Der folgende Script zeigt wie automatisiert über ein PHP-Setup-Script in Magento eine Category angelegt werden kann, welche dann als Default-Category einer neuen Store-Group zugewiesen wird, welche samt einer neuen Store-View angelegt wird.

$installer = $this;
$installer->startSetup();
				$data = array(
								'name' 							=> 'New Category',
								'url_key'    				=> 'root', //'de',
				      	'description' 			=> 'test category',
				      	'meta_description' 	=> 'test category',
								'meta_keywords'			=> 'categories_meta',
								'display_mode'      => Mage_Catalog_Model_Category::DM_PRODUCT,
								'default_sort_by'   => Mage::getModel("catalog/category")->getDefaultSortBy(),
				      	'available_sort_by' => Mage::getModel("catalog/category")->getDefaultSortBy(),
				      	'is_active'					=> 1,
						    'is_anchor'         => 0,
						    'include_in_menu'   => 0,
						    'parent_id'         => 1,
						    'path'              => 1, //Mage::getModel("catalog/category")->load(1)->getPath(),
						    'attribute_set_id'  => Mage::getModel("catalog/category")->getDefaultAttributeSetId(),
								'display_mode'	=> array( '0' => 'show_products'),
								'custom_design_apply' => 1
				        );
				Mage::app()->getStore()->load(0);
				$cat = Mage::getModel('catalog/category');
				$cat->addData($data);
				$parentId = Mage_Catalog_Model_Category::TREE_ROOT_ID;
			  $parentCategory = Mage::getModel('catalog/category')->load($parentId);
			  $cat->setPath($parentCategory->getPath());
			//	$cat->setStoreId(Mage::app()->getStore()->getId());
				$cat->setStoreId(0);
				$cat->setAttributeSetId($cat->getDefaultAttributeSetId());
				try {
				    $cat->save();
				    $newCategoryId = $cat->getId();
				} catch (Exception $e) {
				    Mage::logException($e->getMessage());
				    return;
				}
			}
		if($newCategoryId != '') {
			$groupModel = Mage::getModel('core/store_group');
	    $group = array(
	        'website_id' => 1,
	        'name' => 'New Store Gropu',
	        'root_category_id' => $newCategoryId,
	    );
	    $groupModel->setData($group);
	    $groupModel->setId(null);
	    $groupModel->save();
	    Mage::dispatchEvent('store_group_save', array('group' => $groupModel));
	    $storeModel = Mage::getModel('core/store');
	    $store = array(
	        'group_id' => $groupModel->getId(),
	        'name' => 'New Store',
	        'code' => 'new_store',
	        'is_active' => 1,
	        'sort_order' => 2,
	    );
	    $storeModel->setData($store);
	    $storeModel->setId(null);
	    $eventName = 'store_add';
	    $groupModel = Mage::getModel('core/store_group')->load($storeModel->getGroupId());
	    $storeModel->setWebsiteId($groupModel->getWebsiteId());
	    $storeModel->save();
	    Mage::app()->reinitStores(); // or Mage::app()->getConfig()->reinit();
	    Mage::dispatchEvent($eventName, array('store'=>$storeModel));
		}
$installer->endSetup();
$installer->installEntities();
$installer = $this;
$installer->startSetup(); 

$mobileCategory = Mage::getModel(‚catalog/category‘)->getCollection()
->addAttributeToSelect(‚id‘)
->addAttributeToFilter(’name‘, ‚mobile‘)
->addAttributeToSort(‚id‘, ‚ASC‘)
->distinct(true)
->load();

$mobileCategoryId = “;
if(count($mobileCategory) > 0) {
foreach ($mobileCategory as $value) {
$mobileCategoryId = $value->getId();
}
} else {
$data = array(
’name‘                             => ‚Mobile‘,
‚url_key‘                    => ‚root‘, //’de‘,
‚description‘             => ‚test category‘,
‚meta_description‘     => ‚test category‘,
‚meta_keywords‘            => ‚categories_meta‘,
‚display_mode‘      => Mage_Catalog_Model_Category::DM_PRODUCT,
‚default_sort_by‘   => Mage::getModel(„catalog/category“)->getDefaultSortBy(),
‚available_sort_by‘ => Mage::getModel(„catalog/category“)->getDefaultSortBy(),
‚is_active‘                    => 1,
‚is_anchor‘         => 0,
‚include_in_menu‘   => 0,
‚parent_id‘         => 1,
‚path‘              => 1, //Mage::getModel(„catalog/category“)->load(1)->getPath(),
‚attribute_set_id‘  => Mage::getModel(„catalog/category“)->getDefaultAttributeSetId(),
‚mdm_display_mode‘    => array( ‚0‘ => ’show_products‘),
‚custom_design_apply‘ => 1
);

Mage::app()->getStore()->load(0);
$cat = Mage::getModel(‚catalog/category‘);
$cat->addData($data);
$parentId = Mage_Catalog_Model_Category::TREE_ROOT_ID;
$parentCategory = Mage::getModel(‚catalog/category‘)->load($parentId);
$cat->setPath($parentCategory->getPath());
//    $cat->setStoreId(Mage::app()->getStore()->getId());
$cat->setStoreId(0);
$cat->setAttributeSetId($cat->getDefaultAttributeSetId());

try {
$cat->save();
$mobileCategoryId = $cat->getId();

} catch (Exception $e) {
Mage::logException($e->getMessage());
return;
}
}

if($mobileCategoryId != “) {
$groupModel = Mage::getModel(‚core/store_group‘);
$group = array(
‚website_id‘ => 1,
’name‘ => ‚Mobile‘,
‚root_category_id‘ => $mobileCategoryId, // 119

);

$groupModel->setData($group);
$groupModel->setId(null);
$groupModel->save();

Mage::dispatchEvent(’store_group_save‘, array(‚group‘ => $groupModel));

$storeModel = Mage::getModel(‚core/store‘);

$store = array(
‚group_id‘ => $groupModel->getId(),
’name‘ => ‚Mobile‘,
‚code‘ => ‚mobile‘,
‚is_active‘ => 1,
’sort_order‘ => 2,
);
$storeModel->setData($store);
$storeModel->setId(null);
$eventName = ’store_add‘;

$groupModel = Mage::getModel(‚core/store_group‘)->load($storeModel->getGroupId());
$storeModel->setWebsiteId($groupModel->getWebsiteId());
$storeModel->save();

Mage::app()->reinitStores(); // or Mage::app()->getConfig()->reinit();

Mage::dispatchEvent($eventName, array(’store’=>$storeModel));
}

$installer->endSetup();
$installer->installEntities();

Magento: Per PHP Setup Script neue Store View anlegen

28. Juni 2011 at 11:01

Per PHP Script eine neue Store View über z.B. Setup-Install-Script anlegen?
So geht’s:

$storeModel = Mage::getModel('core/store');
 $store = array(
 'group_id' => 1,
 'name' => 'New Store Name',
 'code' => 'store_xy',
 'is_active' => 1,
 'sort_order' => 2,
 );
 $storeModel->setData($store);
 $storeModel->setId(null);
 $eventName = 'store_add';
 $groupModel = Mage::getModel('core/store_group')->load($storeModel->getGroupId());
 $storeModel->setWebsiteId($groupModel->getWebsiteId());
 $storeModel->save();
 Mage::app()->reinitStores(); // or Mage::app()->getConfig()->reinit();
 Mage::dispatchEvent($eventName, array('store'=>$storeModel));

Magento: Artikel filtern nach bestimten Parametern

17. Juni 2011 at 10:49

Artikel könnt ihr wie folgt nach bestimmten Parametern filtern. Folgendes Beispiel zeigt die Filterung anhand des Preises aus bestimmten Unterkategorien:

<?php
$model = Mage::getModel('catalog/product');     // Direktzugriff auf Produkt als Methode
$collection = $model -> getCollection();    //Zugrif auf Eigenschaft
$collection -> addAttributeToSelect('name');    //Attributaktivierung - Name
//$collection  -> load();                      //Zeigt alle Artikel
$collection -> addFieldToFilter('price',array('from'=>'0','to'=>'40')); //Filtert alle Artikel von 0 bis 40€.
$collection -> getSelect();
$collection -> setOrder('price', 'ASC');
?>
<ul><?php foreach($collection as $product) : ?>
 <li>
 <?php echo $product ->getPrice(); echo "&euro; - "; ?>
 <?php echo $product ->getName(); echo " - ";?>
 <?php echo $product ->getColor(); echo " ";?>
 </li>
<?php  endforeach; ?>
</ul>

Magento – add produkt about remote URL in cart – Magento HowTo

18. Mai 2011 at 14:39

With this url structure you can add simply products to your cart in Magento:

http://www.yourdomain.com/checkout/cart/add?product=[id]&qty=[qty]

The [id] is the Magento ID of the product and [qty] is the Quantity of the product you wish to add.

Add a simple product with custom options to your cart in Magento:

http://www.yourdomain.com/checkout/cart/add?product=[id]&qty=[qty]&options[id]=[value]

The [id] is the Magento ID of the product and [qty] is the Quantity of the product you wish to add and the options[id]=[value] select your option of this product (color, size, etc.).