I have already added custom table called quantities in database. I want to show this as drop down in front end.
$model = Mage::getModel('quantities/quantities')->load($_product->getId());
How to fetch this data and show as dropdown. I am new to Magento.
Thanks in Advance.
You could try this:
$model = Mage::getModel('quantities/quantities')->load($_product->getId());
<select>
<?php foreach($model->getData() as $_data): ?>
<option><?php echo $_data->getYourAttribute() ?></option>
<?php endforeach; ?>
</select>
Granted you know what data is contained in your model. If not just var_dump($_data) or you can print_r($_data)
In the template (*.phtml) file, using Magento Block like this...
<?php
$select = $this->getLayout()->createBlock('core/html_select')
->setName('data['.$selectName.']')
->setId("sel_$selectId")
->setClass('quantity-select')
->setOptions($model->getData())
->setValue($value);
echo $select->getHtml();
?>
or Building it from scratch...
<select name="sel_name" id="sel_id">
<option><?php echo $this->__('Choose an Option...') ?></option>
<?php foreach ($model->getData() as $key => $value): ?>
<option value="<?php echo $key; ?>"><?php echo $value; ?></option>
<?php endforeach; ?>
</select>
Will this do?
Related
I'm figuring out about Magento 2 layered navigation. I want to make this navigation with dropdown lists.
I try this code:
<select onchange="setLocation(this.value)">
<option value=""><?php echo 'Choose an Option...' ?></option>
<?php foreach ($this->getItems() as $_item): ?>
<option
<?php if ($_item->getCount() > 0): ?>
value="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?>
<?php else: echo '>' . $_item->getLabel() ?>
<?php endif; ?>
(<?php echo $_item->getCount() ?>)
</option>
<?php endforeach ?>
</select>
but I am getting the error "setLocation(this.value) is not defined". If anyone has another option, please let me know.
Please add below js code:
function setLocation(value) {
window.location = value;
}
I tried:
<option value="<?php echo $this->getOrderUrl('topsellings', 'desc') ?>"<?php if ($this->isOrderCurrent('topsellings') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
Most Popular
</option>
<option value="<?php echo $this->getOrderUrl('special_price', 'desc') ?>"<?php if ($this->isOrderCurrent('special_price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
On Sale
</option>
but unable to get it. See here for the site. What am I missing?
To add a “custom” attribute, you must add the attribute into the array in the toolbar.php file. You can redeclare it(/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php ).
protected function _construct()
{
parent::_construct();
$this->_availableOrder = array(
'position' => $this->__('Best Value'),
'entity_id' => $this->__('Newest'),
'name' => $this->__('Name'),
'price' => $this->__('Price'),
'format' => $this->__('Format'),
//Custom attribute you have added.
'release_date' => $this->__('Release Date')
);
then you can call the attribute from the array this by adding into the original thread posters code.
<option value="<?php echo $this->getOrderUrl('release_date', 'desc') ?>"<?php if($this->isOrderCurrent('release_date') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
Release Date
</option>
If you set the attribute value of field used_for_sort_by then the template should pick this change up and you will not need to change the template code. This can be done either via a setup script or can easily be set via the attribute management part admin section.
The function getAttributesUsedForSortBy in Mage_Catalog_Model_Config will look for all attributes that have this flag set to true. The default template will update automatically becuase of the following.
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
<?php echo $this->__($_order) ?>
</option>
<?php endforeach; ?>
I have to display product attribute filters(dropdowns) on list page toolbar. any body tell me how to put filters on list page?
The code I am trying to use is:
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
I put a filter in the toolbar section using the below code. I am not getting any result. metal_type is an attribute which has options "Gold" and "Silver" .
<select id='filter' onchange="ajaxfunction()">
<?php foreach($_productCollection as $product): ?>
<option value="<?php $product->getmetal_type() ?>"><?php $product->getmetal_type() ?></option>
<?php endforeach; ?>
You can do manually, by load one collection on starts of the page.
$collection = Mage::getModel('catalog/product')->getCollection();
And you put you combo box like this:
<select id='filter' onchange="ajaxfunction()">
<?php foreach($collection as $product): ?>
<option value="<?= $product->getAttributeYouWantUseToFilter()" ?>"><?= $product->getAttributeYouWantUseToFilter()" ?></option>
<?php endforeach; ?>
</select>
On ajax you call your action to filter.
I am using dropdowns to display my layered navigation attribute values. I have 3 filters - price, size and color.
This is what I am trying to do:
1. Get dropdowns for the layered navigation filters.
2. Get the attribute label/name to show up as the first option. Currently, my code puts a default "Choose an Option" value for each dropdown, which I would like to replace with something like "Choose Price", "Choose Size" and "Choose Color".
Here is my current code for template/catalog/layer/filter.phtml. The dropdown works, but I am stuck at getting the attribute label instead of "Choose an Option"
<select onchange="setLocation(this.value)">
<option value='' disabled selected style='display:none;'>Choose an Option</option>
</option>
<?php foreach ($this->getItems() as $_item): ?>
<option
<?php if ($_item->getCount() > 0): ?>
value="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?>
<?php else: echo '>' . $_item->getLabel() ?>
<?php endif; ?>
(<?php echo $_item->getCount() ?>)
</option>
Try this code. It is tested in all the browsers.
<select onchange="setLocation(this.value)">
<?php $count = 0; ?>
<?php foreach ($this->getItems() as $_item): ?>
<?php $count++; ?>
<?php if($count == 1): ?>
<option value='' disabled selected style='display:none;'>Choose <?php echo $attribute_code = $_item->getFilter()->getName();?> </option>
<?php endif; ?>
<option <?php if ($_item->getCount() > 0): ?> value="<?php echo $this->urlEscape($_item->getUrl()) ?>">
<?php echo $_item->getLabel() ?> <?php else: echo '>' . $_item->getLabel() ?> <?php endif; ?> (<?php echo $_item->getCount() ?>) </option>
<?php endforeach; ?>
</select>
Situation right now:
I've got a live-system and its running very well.
I DO NOT have a testing system.
Our live-system is a multi-store with several storeviews on one website.
PROBLEM:
I need to to add one more storeview and work on that within that livesystem. How can I restrict access to this storeview, so that no customer, whether logged in or not, can see this store? Is this even possible?
I need just an admin (me) to access this storeview.
Sure, I could disable all storeswitcher in the other live-stores but I don't think, this would be a nice solution to my problem. :)
If you do not want to show up currently edited store (view) on your language dropdown select field, do the following:
Add a new customer-group called "admins" to your shop and remember the id which appears in the list.
If not already done, add a new customer for the admin and assign it to the just created customer-group
Go to system->store-view and click on the link in the StoreView Name - column which you dont want to show up on the frontend and klick it, you'll see the StoreView id in the url /index.php/admin/system_store/editStore/store_id/3/key/, remember it
Now edit the file: app/design/frontend/default/your_shop/template/page/switch/languages.phtml
from:
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<label for="select-language"><?php echo $this->__('Your Language:') ?></label>
<select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
<?php foreach ($this->getStores() as $_lang): ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
<option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($_lang->getName()) ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
to:
<?php
// StoreView-Ids we dont want to show on frontend
$stores = array(3);
// Set admin group id with access to the above storeviews
$frontendAdminGroupId = 5;
// Get current user group id
$currentGroupId = $this->helper('customer')->getCurrentCustomer()->group_id;
?>
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<label for="select-language"><?php echo $this->__('Your Language:') ?></label>
<select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
<?php foreach ($this->getStores() as $_lang): ?>
<?php foreach ($stores as $_adminStore) : ?>
<?php /* Admin Store! */?>
<?php if($_adminStore == $_lang->getId() ) : ?>
<?php if($currentGroupId == $frontendAdminGroupId) : ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
<option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($_lang->getName()) ?></option>
<?php endif; ?>
<?php else: ?>
<?php /* Normal User! */?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
<option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($_lang->getName()) ?></option>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
you also have to edit the checkout and any other part of magento which shows up a select field for the store view, that's just a half solution. good luck :-)
If you use Magento Enterprise you are given a staging site where you would be able to make these changes before pushing them out to production.
Or, you can do as #Anton S above said and create a development site. You would use Magento's export functionality to move changes over. NOT a full database dump/import. That way you won't lose any customer and order information.