Magento: Create shipment from order

18. November 2010 at 15:35

You want to create a shipment from an order?
here is the solution in php (example with invoice-data) :

$order = Mage::getModel('sales/order')->loadByIncrementId($invoice->getOrder()->getIncrementId());
if($order->canShip())
{
 $_itemQty                 = $order->getItemsCollection()->count();
 $_shipment             = Mage::getModel('sales/service_order', $order);
 $_shipment             = new Mage_Sales_Model_Order_Shipment_Api();
 $_shipmentId         = $_shipment->create($order->getIncrementId());
}

in phpMyAdmin Session timeout verlängern / verändern

10. November 2010 at 12:34

Gerade bei der lokalen Entwicklung kann das ständige session-timeout echt nerven. Um die Session-Time zu verlängern ergänzt die config.inc.php von phpMyAdmin mit der folgenden Zeile:

$cfg['LoginCookieValidity'] = 3600 * 9; // 9 hours

Magento: Neues Kategorie Attribute hinzufügen / Adding category attributes

28. September 2010 at 16:13

Add a mysql setup file inside the directory of your module YourNamespace/YourModule/sql/yourmodule_setup/ and write the following code in your module’s mysql setup file:

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$setup->addAttribute('catalog_category', 'my_attribute', array(
 'group'         => 'General',
 'input'         => 'text',
 'type'          => 'varchar',
 'label'         => 'My Attribute',
 'backend'       => '',
'frontend'      => '',
 'visible'       => 1,
 'required'      => 0,
 'user_defined' => 1,
 'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
 'visible_on_front' => 1,
'unique'       => 0,
));
// add attribute to group
$installer->addAttributeToGroup('catalog_category', 'Default', 'my_module', 'my_attribute');
$installer->endSetup();

Now you found the code my_attribute and the label My Attribute. You can find it under Admin Panel / Catalog / Manage Categories / General Information .

With the array param ’sort_order‘ you can define the order in the backend-list.

Magento: expand „sort by“ list – „sortieren nach“ Liste erweitern

28. September 2010 at 11:20

you want to expand the default sort by list, without add new attributes? The solution:

extends the class Mage_Catalog_Model_Config and overwrite the function getAttributeUsedForSortByArray() with your own custom option array, f.e. :

class YourNamespace_Catalog_Model_Config extends Mage_Catalog_Model_Config
{
 /**
 * Retrieve Attributes Used for Sort by as array
 * key = code, value = name
 *
 * @return array
 */
 public function getAttributeUsedForSortByArray()
 {
 $custom_options = array(
 'custom_selection' => Mage::helper('catalog')->__('Custom Selection'),
 'newest_first'        => Mage::helper('catalog')->__('Newest first'),
 'bestselling'        => Mage::helper('catalog')->__('Bestselling first'),
 'promotions_first'    => Mage::helper('catalog')->__('Promotions first'),
 'price_htl'            => Mage::helper('catalog')->__('High to low'),
 'Price_lth'            => Mage::helper('catalog')->__('Low to high')
 );
 return $custom_options;
 /*
 * no further sortable attributes needed.
 *
 $options = parent::getAttributeUsedForSortByArray();
 return $custom_options + $options;
 */
 }
}

Magento – Check if user is logged in – Prüfen ob ein user eingeloggt

22. September 2010 at 11:55

You want to check if a user is logged in with Magento? This is the solution:

<?php
if ($this->helper('customer')->isLoggedIn()) {
 echo("Authenticated user");
}
else {
echo("Anonymous user");
}
?>

Magento – Get the total price of items which currently in the cart – Gesamtpreis des Warenkorbes

22. September 2010 at 11:49

You need in Magento the total price of the items which currently in the shopping cart? This is the solution:

<?php echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); ?>

PHP: SSL certificate problem – certificate verify failed

2. September 2010 at 17:34

Bekommt ihr eine Fehlermeldung ähnlich

SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

so ist die  Ursache ein fehlerhaftes bzw. ungültiges SSL-Zertifikat. Läuft der Script local (z.B. während der Entwicklung) so könnt ihr den SSL-Check mit den folgenden Zeilen deaktivieren:

$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;

Magento: Redirect Funktionen

20. August 2010 at 17:42

Die ReDirect Funktionen findet ihr in der Mage_Core_Controller_Varien_Action class.

/* Redirect to certain url  */
_redirectUrl($url)

/* Redirect to certain path */
_redirect($path, $arguments=array())

/* Redirect to success page */
_redirectSuccess($defaultUrl)

/* Redirect to error page */
_redirectError($defaultUrl)

/* Set referer url for redirect in response */
_redirectReferer($defaultUrl=null)

/*  Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param) */
_getRefererUrl()

/* Check url to be used as internal */
_isUrlInternal($url)

For redirect URL:
$url = "http://example.com";
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
For redirect with path and arguments:
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl($path, $arguments));

Magento: Session Variable – Set Unset Session Variable

20. August 2010 at 15:48

Es wird eine individuelle Variable mit den Namen „magentoTest“ angelegt. Der Wert für diese ist in diesem Fall „hello magento“.

$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$session->setMagentoTest('hello magento');

Abfragen der Werte:

$test = Mage::getSingleton('core/session')->getMagentoTest();

Session Variable löschen / unset

Mage::getSingleton('core/session')->setMagentoTest();

Nur eine bestimmte Session-Variable löschen:

Mage::getSingleton('core/session')->unsMagentoTest();

(Im Frontend die Customer oder Core Session benutzen. Im Backend die Adminhtml Session benutzen.)
Core Session:- Mage::getSingleton(‘core/session’)
Customer Session:- Mage::getSingleton(‘customer/session’)
Admin Session:- Mage::getSingleton(‘adminhtml/session’)

Magento: Statischen CMS Block im Template ausgeben

10. Juli 2010 at 16:27

Ihr könnt in Magento ein statischen CMS Block wie folgt im template einbinden.

Ein Beispiel zum einbinden über die entsprechende layout.xml :

<layout>
<asdf_xy_zzz>
<reference name="content">
 <block type="cms/block" name="cms_store_check">
 <action method="setBlockId"><block_id>store_check</block_id></action>
 </block>
 </reference>
 </asdf_xy_zzz>
</layout>

Direkt einbinden im Template:

echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_id')->toHTML();?>

Einbinden im CMS:

{{block type="cms/block" block_id="your_id" template="cms/content.phtml"}}