Banner - Blog zu den Themen Programmierung, SEO, SEM, Social Media, Internet Marketing, Webdesign, IT-Service und Mehr - SEO Hannover - IT-Dienstleistungen und SEO Agentur Fly2Mars-Media.de

Archiv

Artikel Tagged ‘Magento’

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

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>
GD Star Rating
loading...
GD Star Rating
loading...
KategorienMagento, PHP, Programmierung Tags: ,

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

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();

GD Star Rating
loading...
GD Star Rating
loading...
KategorienMagento, PHP, Programmierung Tags: , ,

Magento: Per PHP Setup Script neue Store View anlegen

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));
GD Star Rating
loading...
GD Star Rating
loading...

Magento: Artikel filtern nach bestimten Parametern

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>
GD Star Rating
loading...
GD Star Rating
loading...
KategorienMagento, PHP, Programmierung Tags: ,

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

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.).

GD Star Rating
loading...
GD Star Rating
loading...
KategorienMagento Tags: ,

Magento Online Doku / Documentation

Eine strukturierte Online Doku inkl. Datenstruktur, Klassenhierarchie, etc. findet ihr unter folgendem Link:

docs.databyte.at/magento/community/1.5/

GD Star Rating
loading...
GD Star Rating
loading...
KategorienMagento Tags: , , ,

Magento: Session Success or Failure Message after redirect – Magento HowTo

27. April 2011 1 Kommentar

Add a Success, Info or Error Message to the session and save this for re-direction in Magento

//A Success Message
 Mage::getSingleton('checkout/session')->addSuccess("Your cart has been updated successfully!");
 //A Error Message
 Mage::getSingleton('checkout/session')->addError("Your cart has been updated successfully!");
 //A Info Message (See link below)
 Mage::getSingleton('checkout/session')->addNotice("This is just a FYI message...");
 //These two lines are required to get it to work
 session_write_close(); //THIS LINE IS VERY IMPORTANT!
 $this->_redirect('checkout/cart');
GD Star Rating
loading...
GD Star Rating
loading...

Magento: PHP-Code in Content-Seiten (CMS) einbinden – HowTo

26. April 2011 1 Kommentar

Aus Sicherheitsgründen ist es nicht gestattet in Magento-CMS-Pages direkt PHP-Code einzubinden.

Über dem folgenden Weg ist dies möglich:

Im Template Ordner muss dazu eine Datei zum einbinden vorhanden oder angelegt werden. Z.B. die test.phtml welche im Ordner  /app/design/frontend/default/default/test/test.phtml abgelegt wird.

In dieser Datei kann, wie in den phtml-template-files üblich, php-code aufgerufen werden, z.b.:

<strong><?php echo "Hello World"; ?></strong>

In der CMS-Page ruft ihr diese Template-Datei wie folgt auf:

{{block type="core/template" template="test/test.phtml"}}
GD Star Rating
loading...
GD Star Rating
loading...

Magento: Attribute zur Checkout-Quote hinzufügen

Zuerst muss in der Datenbank die Quote Tabelle entsprechend mit dem neuen Attribute erweitert werden, dies geht wie gewohnt über die setup-scripte (z.B. mysql4-install-0.0.X.php):

$installer = $this;
$installer->startSetup();
$installer->addAttribute('quote', 'new_attribute', array(
 'label'                        => 'New Attribute',
 'type'                        => 'varchar',
));
$installer->endSetup();

Danach könnt ihr, z.b. im OnepageController.php dieses Attribute wie folgt mit Werten füllen:

Mage::getSingleton('checkout/session')->getQuote()->setNewAttribute('value');
 Mage::getSingleton('checkout/session')->getQuote()->collectTotals();
 Mage::getSingleton('checkout/session')->getQuote()->save();

Be careful on input and type. Input means the input type of the attribute. And type means the input type in database.

For textfield it will be:
'input' => 'text',
'type' => 'text',

For textarea it will be:
'input' => 'textarea',
'type' => 'text',

For date field it will be:
'input' => 'date',
'type' => 'datetime',

For select list it will be:
'input' => 'select',
'type' => 'text',

For boolean select it will be:
'input' => 'boolean',
'type' => 'int',

GD Star Rating
loading...
GD Star Rating
loading...

Magento: Admin URL für Admin-Backend-Bereich ändern – Anleitung / HowTo

Den Pfad in der URL zum Magento Admin-Backend-Bereich könnt ihrin der local.xml unter app/etc/ im folgenden Bereich ändern:

<admin>
 <routers>
 <adminhtml>
 <args>
 <frontName><![CDATA[admin]]></frontName>
 </args>
 </adminhtml>
 </routers>
 </admin>

 

 

Wichtig ist dabei der Teil wo “Admin” steht bei <frontName><![CDATA[admin]]></frontName>, soll der neue path lauten “admin-admin” ändert den Part wie folgt: <frontName><![CDATA[admin-admin]]></frontName>

GD Star Rating
loading...
GD Star Rating
loading...
KategorienMagento Tags: , , ,