“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
Wednesday, 5 November 2014
Friday, 26 September 2014
Magento Category Accordian with Alphabatically sorting.
Add following code in any PHTML file and call in left/right side.
<div class="block block-left-nav" id="sidebox">
<div class="block-title">
<strong><span><?php echo $this->__('categories') ?></span></strong>
</div>
<div class="block-content">
<ul id="nav-left">
<?php
$collection = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToSelect('is_active')
->addAttributeToSort('name', 'ASC');
foreach ($collection as $_category1):
if ($this->getRequest()->getModuleName() == 'vendor') {
$_category = Mage::getModel('catalog/category')->load($_category1['entity_id']);
?>
<?php if ($_category->getIsActive() && $_category1['entity_id'] != 2 && $_category->getLevel() == 2) { ?>
<?php $potential = $_category->hasChildren(); ?>
<li><a id="block-title" class="<?php echo ($open) ? 'active' : 'inactive' ?>" href="<?php
if ($potential) {
echo $this->getCategoryUrl($_category);
//echo 'javascript:void(0)';
} else {
echo $this->getCategoryUrl($_category);
}
?> "><?php echo $_category->getName(); ?></a>
<?php if ($potential) { ?>
<ul class="top-level">
<?php
$_cat_level_2 = array();
foreach ($_category->getChildrenCategories() as $_category2) {
$_cat_level_2[$_category2->getName()] = $_category2;
}
ksort($_cat_level_2);
?>
<?php foreach ($_cat_level_2 as $subcategory): ?>
<li class="second-category">
<a class="<?php echo ($open) ? 'active' : '' ?>" href="<?php echo $this->getCategoryUrl($subcategory); ?>"><?php echo $subcategory->getName(); ?></a>
<?php if ($potential) { ?>
<ul class="sub-level">
<?php
$_cat_level_3 = array();
foreach ($subcategory->getChildrenCategories() as $_category3) {
$_cat_level_3[$_category3->getName()] = $_category3;
}
ksort($_cat_level_3);
?>
<?php foreach ($_cat_level_3 as $subsubcategory): ?>
<li><a class="<?php echo ($open) ? 'active' : '' ?>" href="<?php echo $this->getCategoryUrl($subsubcategory); ?>"><?php echo $subsubcategory->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php
}
}
else {
$_category = Mage::getModel('catalog/category')->load($_category1['entity_id']);
?>
<?php if ($_category->getIsActive() && $_category1['entity_id'] != 2 && $_category->getLevel() == 2) { ?>
<?php
$open = $this->isCategoryActive($_category);
if (Mage::registry('current_category')->getid() == $_category1['entity_id']) {
$open = 'yes';
}
?>
<?php $potential = $_category->hasChildren(); ?>
<li><a id="block-title" class="<?php echo ($open) ? 'active' : 'inactive' ?>" href="<?php
if ($open) {
echo $this->getCategoryUrl($_category);
} elseif ($potential) {
//echo 'javascript:void(0)';
echo $this->getCategoryUrl($_category);
} else {
echo $this->getCategoryUrl($_category);
}
?> "><?php echo $_category->getName(); ?></a>
<?php if ($potential) { ?>
<?php
$_cat_level_2 = array();
foreach ($_category->getChildrenCategories() as $_category2) {
$_cat_level_2[$_category2->getName()] = $_category2;
}
ksort($_cat_level_2);
?>
<ul class="top-level">
<?php foreach ($_cat_level_2 as $subcategory): ?>
<?php
$open = $this->isCategoryActive($subcategory);
if (Mage::registry('current_category')->getid() == $subcategory->getId()) {
$open = 'yes';
}
?>
<?php $potential = $subcategory->hasChildren(); ?>
<li class="second-category">
<a class="<?php echo ($open) ? 'active' : '' ?>" href="<?php echo $this->getCategoryUrl($subcategory); ?>"><?php echo $subcategory->getName(); ?></a>
<?php if ($potential) { ?>
<ul class="sub-level">
<?php
$_cat_level_3 = array();
foreach ($subcategory->getChildrenCategories() as $_category3) {
$_cat_level_3[$_category3->getName()] = $_category3;
}
ksort($_cat_level_3);
?>
<?php foreach ($_cat_level_3 as $subsubcategory): ?>
<?php
$open = $this->isCategoryActive($subsubcategory);
if (Mage::registry('current_category')->getid() == $subsubcategory->getId()) {
$open = 'yes';
}
?>
<li><a class="<?php echo ($open) ? 'active' : '' ?>" href="<?php echo $this->getCategoryUrl($subsubcategory); ?>"><?php echo $subsubcategory->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php }
}
?>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="block block-left-nav" id="sidebox">
<div class="block-title">
<strong><span><?php echo $this->__('categories') ?></span></strong>
</div>
<div class="block-content">
<ul id="nav-left">
<?php
$collection = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToSelect('is_active')
->addAttributeToSort('name', 'ASC');
foreach ($collection as $_category1):
if ($this->getRequest()->getModuleName() == 'vendor') {
$_category = Mage::getModel('catalog/category')->load($_category1['entity_id']);
?>
<?php if ($_category->getIsActive() && $_category1['entity_id'] != 2 && $_category->getLevel() == 2) { ?>
<?php $potential = $_category->hasChildren(); ?>
<li><a id="block-title" class="<?php echo ($open) ? 'active' : 'inactive' ?>" href="<?php
if ($potential) {
echo $this->getCategoryUrl($_category);
//echo 'javascript:void(0)';
} else {
echo $this->getCategoryUrl($_category);
}
?> "><?php echo $_category->getName(); ?></a>
<?php if ($potential) { ?>
<ul class="top-level">
<?php
$_cat_level_2 = array();
foreach ($_category->getChildrenCategories() as $_category2) {
$_cat_level_2[$_category2->getName()] = $_category2;
}
ksort($_cat_level_2);
?>
<?php foreach ($_cat_level_2 as $subcategory): ?>
<li class="second-category">
<a class="<?php echo ($open) ? 'active' : '' ?>" href="<?php echo $this->getCategoryUrl($subcategory); ?>"><?php echo $subcategory->getName(); ?></a>
<?php if ($potential) { ?>
<ul class="sub-level">
<?php
$_cat_level_3 = array();
foreach ($subcategory->getChildrenCategories() as $_category3) {
$_cat_level_3[$_category3->getName()] = $_category3;
}
ksort($_cat_level_3);
?>
<?php foreach ($_cat_level_3 as $subsubcategory): ?>
<li><a class="<?php echo ($open) ? 'active' : '' ?>" href="<?php echo $this->getCategoryUrl($subsubcategory); ?>"><?php echo $subsubcategory->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php
}
}
else {
$_category = Mage::getModel('catalog/category')->load($_category1['entity_id']);
?>
<?php if ($_category->getIsActive() && $_category1['entity_id'] != 2 && $_category->getLevel() == 2) { ?>
<?php
$open = $this->isCategoryActive($_category);
if (Mage::registry('current_category')->getid() == $_category1['entity_id']) {
$open = 'yes';
}
?>
<?php $potential = $_category->hasChildren(); ?>
<li><a id="block-title" class="<?php echo ($open) ? 'active' : 'inactive' ?>" href="<?php
if ($open) {
echo $this->getCategoryUrl($_category);
} elseif ($potential) {
//echo 'javascript:void(0)';
echo $this->getCategoryUrl($_category);
} else {
echo $this->getCategoryUrl($_category);
}
?> "><?php echo $_category->getName(); ?></a>
<?php if ($potential) { ?>
<?php
$_cat_level_2 = array();
foreach ($_category->getChildrenCategories() as $_category2) {
$_cat_level_2[$_category2->getName()] = $_category2;
}
ksort($_cat_level_2);
?>
<ul class="top-level">
<?php foreach ($_cat_level_2 as $subcategory): ?>
<?php
$open = $this->isCategoryActive($subcategory);
if (Mage::registry('current_category')->getid() == $subcategory->getId()) {
$open = 'yes';
}
?>
<?php $potential = $subcategory->hasChildren(); ?>
<li class="second-category">
<a class="<?php echo ($open) ? 'active' : '' ?>" href="<?php echo $this->getCategoryUrl($subcategory); ?>"><?php echo $subcategory->getName(); ?></a>
<?php if ($potential) { ?>
<ul class="sub-level">
<?php
$_cat_level_3 = array();
foreach ($subcategory->getChildrenCategories() as $_category3) {
$_cat_level_3[$_category3->getName()] = $_category3;
}
ksort($_cat_level_3);
?>
<?php foreach ($_cat_level_3 as $subsubcategory): ?>
<?php
$open = $this->isCategoryActive($subsubcategory);
if (Mage::registry('current_category')->getid() == $subsubcategory->getId()) {
$open = 'yes';
}
?>
<li><a class="<?php echo ($open) ? 'active' : '' ?>" href="<?php echo $this->getCategoryUrl($subsubcategory); ?>"><?php echo $subsubcategory->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php }
}
?>
<?php endforeach; ?>
</ul>
</div>
</div>
Tuesday, 2 September 2014
Magento: Display number of times a product has been sold in the Product Grid
To display how many time product is sold you have to create a rendered in product grid.
Add this code in your admin grid.
class Techtown_Adminx_Block_Adminhtml_Adminx_Renderer_Salesreturn extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$productID = $row->getId();
$product = Mage::getModel('catalog/product')->load($productID);
$sku = nl2br($product->getSku());
//$to = $_product->getResource()->formatDate(time());
//$from = $_product->getResource()->formatDate(time() - 60 * 60 * 24 * 1);
$product = Mage::getResourceModel('reports/product_collection')
->addOrderedQty(true)
->addAttributeToFilter('sku', $sku)
->setOrder('ordered_qty', 'desc')
->getFirstItem();
echo '<a href="#" class="adminx-sales-return-grid">'.(int)$product->ordered_qty.'</a>';
}
}
Add this code in your admin grid.
class Techtown_Adminx_Block_Adminhtml_Adminx_Renderer_Salesreturn extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$productID = $row->getId();
$product = Mage::getModel('catalog/product')->load($productID);
$sku = nl2br($product->getSku());
//$to = $_product->getResource()->formatDate(time());
//$from = $_product->getResource()->formatDate(time() - 60 * 60 * 24 * 1);
$product = Mage::getResourceModel('reports/product_collection')
->addOrderedQty(true)
->addAttributeToFilter('sku', $sku)
->setOrder('ordered_qty', 'desc')
->getFirstItem();
echo '<a href="#" class="adminx-sales-return-grid">'.(int)$product->ordered_qty.'</a>';
}
}
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.
Subscribe to:
Posts (Atom)

