Programmatically add product to cart with price change

After digging a bit into Magento’s core code, I found that you need to use $item->getProduct()->setIsSuperMode(true) in order to make $item->setCustomPrice() and $item->setOriginalPrice() work. Here is some sample code you can use within an Observer that listens for the checkout_cart_product_add_after or checkout_cart_update_items_after events. The code is logically the same except checkout_cart_product_add_after is called for only … Read more

ALTER TABLE in Magento setup script without using SQL

You can use such methods within your setup script: Use Varien_Db_Ddl_Table class to create new tables, where you can configure all the fields, keys, relations in combination with $this->getConnection()->createTable($tableObject) Example: /* @var $this Mage_Core_Model_Resource_Setup */ $table = new Varien_Db_Ddl_Table(); $table->setName($this->getTable(‘module/table’)); $table->addColumn(‘id’, Varien_Db_Ddl_Table::TYPE_INT, 10, array(‘unsigned’ => true, ‘primary’ => true)); $table->addColumn(‘name’, Varien_Db_Ddl_Table::TYPE_VARCHAR, 255); $table->addIndex(‘name’, ‘name’); $table->setOption(‘type’, … Read more

Why is Magento so slow? [closed]

I’ve only been tangentially involved in optimizing Magento for performance, but here’s a few reasons why the system is so slow Parts of Magento use an EAV database system implemented on top of MySQL. This means querying for a single “thing” often means querying multiple rows There’s a lot of things behind the scenes (application … Read more

Magento upgrade takes too long and never completes

I recently upgraded a clients magento from V1.4 to V1.7.2.0 and i followed this steps:- Following are the main points to upgrade the website from Magento v1.4.0.0 to v1.7.2.0:- Collect the live database backup in a zipped format, without the following tables:- “log_customer” “log_quote” “log_summary” “log_url” “log_url_info” “log_visitor” “log_visitor_info” “log_visitor_online” Unzip the zipped backup database, … Read more

Magento products will not show in category

The checklist for whether items are in stock follows. Some will seem stupid until the first time you spend an hour trying to figure this problem out: The products must be Visible in Catalog. The products must be Enabled. Product must have a stock Quantity. The product must be set to In Stock. If the … Read more

Adding attributes to customer entity

This is the code for a basic int attribute with text renderer: $installer = $this; $installer->startSetup(); $setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’); $setup->addAttribute(‘customer’, ‘your_attribute_code_here’, array( ‘input’ => ‘text’, ‘type’ => ‘int’, ‘label’ => ‘Some textual description’, ‘visible’ => 1, ‘required’ => 0, ‘user_defined’ => 1, )); $entityTypeId = $setup->getEntityTypeId(‘customer’); $attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId); $attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); $setup->addAttributeToGroup( … Read more

Changing the price in quote while adding product to cart: magento

The way to do it is add an observer which looks for this event ‘sales_quote_add_item’: <events> <sales_quote_add_item> <observers> <priceupdate_observer> <type>singleton</type> <class>mymodule/observer</class> <method>updatePrice</method> </priceupdate_observer> </observers> </sales_quote_add_item> </events> The observer should have a method which does something like this: public function updatePrice($observer) { $event = $observer->getEvent(); $quote_item = $event->getQuoteItem(); $new_price = <insert logic> $quote_item->setOriginalCustomPrice($new_price); $quote_item->save(); }