“It's not at all important to get it right the first time. It's vitally important to get it right the last time.” - Andrew Hunt and David Thomas
Friday, 11 July 2014
Tuesday, 8 July 2014
Magento Call Java script Function in XML Top links.
<reference name="top.links">
<action method="addLink" translate="label title" module="smartproductfinder">
<label>Smart Product Finder</label>
<title>javascript:void(0)</title>
<prepare/><aParams/>
<position>10</position>
<li/><a>data-reveal-id="myModal"</a>
</action>
</reference>
<action method="addLink" translate="label title" module="smartproductfinder">
<label>Smart Product Finder</label>
<title>javascript:void(0)</title>
<prepare/><aParams/>
<position>10</position>
<li/><a>data-reveal-id="myModal"</a>
</action>
</reference>
Magento Display Dropdown For Quntity Box
In the addtocart.phtml file find the following code(line 33)
<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />
Replace with this code:
This code shows the “Available Qty for Product”.
<select class="input-text qty" name="qty" id="qty">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i?>">
<?php echo $i?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) ?></select>
This code shows the “Maximum Qty Allowed in Shopping Cart”.
<select class="input-text qty" name="qty" id="qty">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i ?>">
<?php echo $i ?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getMaxSaleQty()) ?>
</select>
<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />
Replace with this code:
This code shows the “Available Qty for Product”.
<select class="input-text qty" name="qty" id="qty">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i?>">
<?php echo $i?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) ?></select>
This code shows the “Maximum Qty Allowed in Shopping Cart”.
<select class="input-text qty" name="qty" id="qty">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i ?>">
<?php echo $i ?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getMaxSaleQty()) ?>
</select>
Magento Add Date Filed In Admin Form
Step-1 Add the following code in app/code/local/YourNamespace/YourModule/Block/Adminhtml/Yourmodule/Edit/Tab/Form.php
$fieldset->addField('purchase_date', 'date', array(
'label' => Mage::helper('subscription')->__('Purchase Date'),
'name' => 'purchase_date',
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
));
Step-2 Now the date field with a datepicker is displayed in your admin form. To save the value into database, you need to add a line of code in saveAction() function of app/code/local/YourNamespace/YourModule/controllers/YourModuleController.php
if ($data = $this->getRequest()->getPost()) {
$data = $this->_filterDates($data, array('purchase_date', 'expiry_date'));
$model = Mage::getModel('subscription/subscription');
$model->setData($data)
->setId($this->getRequest()->getParam('id'));
Hope it helps. Thanks.
$fieldset->addField('purchase_date', 'date', array(
'label' => Mage::helper('subscription')->__('Purchase Date'),
'name' => 'purchase_date',
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
));
Step-2 Now the date field with a datepicker is displayed in your admin form. To save the value into database, you need to add a line of code in saveAction() function of app/code/local/YourNamespace/YourModule/controllers/YourModuleController.php
if ($data = $this->getRequest()->getPost()) {
$data = $this->_filterDates($data, array('purchase_date', 'expiry_date'));
$model = Mage::getModel('subscription/subscription');
$model->setData($data)
->setId($this->getRequest()->getParam('id'));
Hope it helps. Thanks.
Tuesday, 24 June 2014
Magento Create Limited & Random Product List.
In my case i have create featured product list with product 10 and it display randomaly.
Please copy past following code in your collection block file.
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$collection = Mage::getModel('catalog/product')->getCollection();
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addAttributeToFilter('featured_product', 1)
->addTaxPercents();
$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$collection->setPage(1, 10)->load();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
Please copy past following code in your collection block file.
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$collection = Mage::getModel('catalog/product')->getCollection();
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addAttributeToFilter('featured_product', 1)
->addTaxPercents();
$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$collection->setPage(1, 10)->load();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
Magento Sort Category(Navigation) By Name or Alphabatically.
To sort Top Menu Categories and its Sub-Categoiries alphabetically,
Copy app/code/core/Mage/Catalog/Block/Navigation.php to app/code/local/Mage/Catalog/Block/Navigation.php OR you can override the same file in your local
public function toLinearArray($collection)
{
$array = array();
foreach ($collection as $item) $array[] = $item;
return $array;
}
protected function _sortCategoriesByName($cat1, $cat2)
{
return strcasecmp($cat1->getName(), $cat2->getName());
}
In Navigation.php edit the function _renderCategoryMenuItemHtml(), add the following 2 lines before the code $hasChildren = ($children && $childrenCount);
$children = $this->toLinearArray($children);
usort($children, array($this, '_sortCategoriesByName'));
If you need to sort Parent Categories too, use below code before your foreach loop when you display category list
<?php $helper = Mage::helper('catalog/category') ?>
<?php $categories = $helper->getStoreCategories(); ?>
<?php $children = $this->toLinearArray($categories);
usort($children, array($this, '_sortCategoriesByName'));?>
<?php foreach ($children as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
Copy app/code/core/Mage/Catalog/Block/Navigation.php to app/code/local/Mage/Catalog/Block/Navigation.php OR you can override the same file in your local
public function toLinearArray($collection)
{
$array = array();
foreach ($collection as $item) $array[] = $item;
return $array;
}
protected function _sortCategoriesByName($cat1, $cat2)
{
return strcasecmp($cat1->getName(), $cat2->getName());
}
In Navigation.php edit the function _renderCategoryMenuItemHtml(), add the following 2 lines before the code $hasChildren = ($children && $childrenCount);
$children = $this->toLinearArray($children);
usort($children, array($this, '_sortCategoriesByName'));
If you need to sort Parent Categories too, use below code before your foreach loop when you display category list
<?php $helper = Mage::helper('catalog/category') ?>
<?php $categories = $helper->getStoreCategories(); ?>
<?php $children = $this->toLinearArray($categories);
usort($children, array($this, '_sortCategoriesByName'));?>
<?php foreach ($children as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
Wednesday, 18 June 2014
Magento Product Attribute Show/Hide in Admin Depending on Other Attribute Value
Please past this code in design/adminhtml/catalog/product/edit.phtml
<script type="text/javascript">
Event.observe(window, 'load', function() {
var $delDay = $("featured"); // featured is yes/no dropdown id
if ($delDay.value == 0) {
$('featured_position').value = ''; // delivery_time is show.hide attribute name
$('featured_position').disable()
}
});
Event.observe($("featured"), 'change', function() {
var $delDay = $("featured");
if ($delDay.value == 1) {
$('featured_position').enable();
}
else {
$('featured_position').value = '';
$('featured_position').disable();
}
});
</script>
<script type="text/javascript">
Event.observe(window, 'load', function() {
var $delDay = $("featured"); // featured is yes/no dropdown id
if ($delDay.value == 0) {
$('featured_position').value = ''; // delivery_time is show.hide attribute name
$('featured_position').disable()
}
});
Event.observe($("featured"), 'change', function() {
var $delDay = $("featured");
if ($delDay.value == 1) {
$('featured_position').enable();
}
else {
$('featured_position').value = '';
$('featured_position').disable();
}
});
</script>
Subscribe to:
Posts (Atom)