Magento: Show gift card details in admin order page
Magento display gift card details (code and amount) in Order View page of admin panel. When customer uses gift card in their order Magento does not display gift card code and amount details in admin panel which makes it tough to know. Customer can pay partially through gift card which makes even tougher as Magento only shows payment information of other method and not gift card amount deductions.
Below code will show you an additional block in magento admin panel with Gift Card details. If gift card is not used in an order, the block will simply no shown.
Open the file app/design/adminhtml/default/default/template/sales/order/view/edit.phtml
Add the below lines of code anywhere you want the gift card block to appear. I have used it after Account Information block.
<?php $cards = unserialize($_order->getGiftCards()); | |
if($cards!='' && count($cards)>0) { ?> | |
<div class="box-left"> | |
<div class="entry-edit"> | |
<div class="entry-edit-head"> | |
<h4 class="icon-head head-account"><?php echo Mage::helper('sales')->__('Gift Cards') ?></h4> | |
</div> | |
<div class="fieldset"> | |
<div class="hor-scroll"> | |
<table cellspacing="0" class="form-list"> | |
<?php foreach ($cards as $card) { ?> | |
<tr> | |
<td class="label"><label><?php echo Mage::helper('sales')->__('Giftcard Code') ?></label></td> | |
<td class="value"> | |
<div style="font-weight:bold"><?php echo $card['c'];?></div> | |
</td> | |
</tr> | |
<tr> | |
<td class="label"><label><?php echo Mage::helper('sales')->__('Giftcard Amount') ?></label></td> | |
<td class="value"> | |
<div style="font-weight:bold"><?php echo $card['a'];?></div> | |
</td> | |
</tr> | |
<?php }?> | |
</table> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php }?> |
Magento add/remove product attribute programatically
Magento add product attribute using sql setup file in your module. Also assign your custom attribute to attribute set Default and group General programatically.
Below code will add your new attribute in Manage Products edit screen at the end of General tab with dropdown values Yes/No. It will not display in frontend website but you can change visibible on front to 1 if you wish. Note that it will assign to Default attribute set only but you can change it to whatever as per your requirement.
$model = Mage::getResourceModel('catalog/setup','catalog_setup'); | |
$data=array( | |
'type'=>'int', | |
'input'=>'boolean', //for Yes/No dropdown | |
'sort_order'=>50, | |
'label'=>'CUSTOM ATTRIBUTE CODE LABEL', | |
'global'=>Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, | |
'required'=>'0', | |
'comparable'=>'0', | |
'searchable'=>'0', | |
'is_configurable'=>'1', | |
'user_defined'=>'1', | |
'visible_on_front' => 0, //want to show on frontend? | |
'visible_in_advanced_search' => 0, | |
'is_html_allowed_on_front' => 0, | |
'required'=> 0, | |
'unique'=>false, | |
'apply_to' => 'configurable', //simple,configurable,bundled,grouped,virtual,downloadable | |
'is_configurable' => false | |
); | |
$model->addAttribute('catalog_product','CUSTOM_ATTRIBUTE_CODE',$data); | |
$model->addAttributeToSet( | |
'catalog_product', 'Default', 'General', 'CUSTOM_ATTRIBUTE_CODE' | |
); //Default = attribute set, General = attribute group |
To remove the product attribute using the setup file, use below code instead:
$model = Mage::getResourceModel('catalog/setup','catalog_setup'); | |
$model->removeAttribute('catalog_product','CUSTOM_ATTRIBUTE_CODE'); |
Magento set session cookie lifetime to 1 day
Is your Magento shopping cart kicking out all the items after 24 minutes? Are you frustrated because your customer’s cart items are getting flushed every few hours even though you have correct setting in Magento? Do you want to increase your shopping cart sessions to last for 1 day (or anything you wish)?
Here are the things to look for to increase/decrease Magento’s session cookie lifetime.
In your php.ini file:
session.gc_maxlifetime 86400 |
If you have not changed this, it should be by default 1440 i.e. 24 minutes. Change it to 86400 for one day session lifetime
In your Magento admin:
System -> Configuration -> Checkout -> Shopping Cart | |
Quote Lifetime (days) -> 1 |
System -> Configuration -> Web -> Session Cookie Management | |
Cookie Lifetime -> 86400 |
Make sure to check if you are in correct website/store if using multi-website/multi-store Magento setup. You can change the scope by changing the website/store from the upper left Store Switcher drop down in System -> Configuration screen.
If you are changing php.ini value, make sure you reload apache to reflect the changes.
Magento reload top mini cart programatically
Magento reload/refresh top mini cart programatically. This can be useful when you are using ajax to add/remove product to cart and want to reflect that item changes in the top cart immediately. Simply put below code where you are modifying cart programatically and it will start working.
Right now it’s only coded for simple and configurable products, but you can add bundle, group, virtual and downloader product item renderers too if you are using them in your website.
$b = $this->getLayout() | |
->createBlock('checkout/cart_sidebar') | |
->addItemRender('simple', 'checkout/cart_item_renderer', 'checkout/cart/sidebar/default.phtml') | |
->addItemRender('configurable', 'checkout/cart_item_renderer_configurable', 'checkout/cart/sidebar/default.phtml') | |
->setTemplate('checkout/cart/cartheader.phtml') | |
->toHtml(); |
Magento auto remove out of stock items from shopping cart
Magento automatically remove product items from shopping cart page which are out of stock. You may need this feature when the situation aries where product goes out of stock and that particular product is already there in other customer’s cart who have not yet checked it out. With this script Magento will auto-check if all the items in the cart are available and in-stock before proceeding for checkout page.
In config.xml file:
<events> | |
<controller_action_predispatch_checkout_cart_index> | |
<observers> | |
<namespace_module_autoremove_outofstock> | |
<type>singleton</type> | |
<class>namespace_module/observer</class> | |
<method>autoRemoveOutOfStockItems</method> | |
</namespace_module_autoremove_outofstock> | |
</observers> | |
</controller_action_predispatch_checkout_cart_index> | |
</events> |
In Observer.php file:
public function autoRemoveOutOfStockItems($observer) { | |
$quote = Mage::getModel('checkout/session')->getQuote(); | |
$cartItems = $quote->getAllItems(); | |
foreach ($cartItems as $item) | |
{ | |
//$productType = $item->getProduct()->getTypeId(); | |
//if($productType!='configurable') { | |
$productId = $item->getProductId(); | |
$product = Mage::getModel('catalog/product')->load($productId); | |
$stockItem = $product->getStockItem(); | |
if(!$stockItem->getIsInStock()) | |
{ | |
Mage::helper('checkout/cart')->getCart()->removeItem($item->getId())->save(); | |
} | |
//} | |
} | |
} |
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)