How to make dropdown layered navigation in Magento 2 - magento

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;
}

Related

Magento language switcher how to show unselected language

Please I need your help to show unselected language instead of the selected.
in other words, if you open default language (English) will load and in the top bar will show English to click on it to change to French so i need to show French if the store using English view and same if using French view will show English in topbar.
<?php if(count($this->getStores())>1): ?>
<div class="form-language top-select">
<select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value" style="width:auto;">
<?php foreach ($this->getStores() as $_lang): ?>
<?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
<option value="<?php echo $_lang->getCurrentUrl() ?>" <?php if($lang_flag): ?> data-image="<?php echo $this->getSkinUrl('images/flags/'.$_lang->getCode().'.png'); ?>" <?php endif; ?> <?php echo $_selected ?>><?php echo $this->htmlEscape($_lang->getName()) ?></option>
<?php endforeach; ?>
</select>
<script type="text/javascript">
(function($){
$("#select-language").selectbox();
})(jQuery);
</script>
</div>
<?php endif; ?>

magento mobileshoppe theme - Fatal error: Call to a member function getSize() on a non-object in

I am using mobileshoppe magento theme for our store, when i installed magento it was showing latest products on home page using the code below.
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}
Then we customized the theme and it stopped to display latest products on home page even the code above is as it is in admin.
It shows the error -
Fatal error: Call to a member function getSize() on a non-object in D:\wamp\www\magento\app\design\frontend\default\mobileshoppe\template\catalog\product\list\toolbar_top.phtml on line 34
toolbar_top.phtml
<?php if($this->getCollection()->getSize()): ?>
<div class="toolbar">
<?php if( $this->isExpanded() ): ?>
<div class="sorter">
<?php if( $this->isEnabledViewSwitcher() ): ?>
<p class="view-mode">
<?php $_modes = $this->getModes(); ?>
<?php if($_modes && count($_modes)>1): ?>
<label><?php echo $this->__('View as') ?>:</label>
<?php foreach ($this->getModes() as $_code=>$_label): ?>
<?php if($this->isModeActive($_code)): ?>
<strong title="<?php echo $_label ?>" class="<?php echo strtolower($_code); ?>"><?php echo $_label ?></strong>
<?php else: ?>
<?php echo $_label ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</p>
<?php endif; ?>
<div class="limiter">
<label><?php echo $this->__('Show') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach ($this->getAvailableLimit() as $_key=>$_limit): ?>
<option value="<?php echo $this->getLimitUrl($_key) ?>"<?php if($this->isLimitCurrent($_key)): ?> selected="selected"<?php endif ?>>
<?php echo $_limit ?>
</option>
<?php endforeach; ?>
</select> <?php echo $this->__('per page') ?>
</div>
<div class="sort-by">
<label><?php echo $this->__('Sort By') ?></label>
<select onchange="setLocation(this.value)">
<?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; ?>
</select>
<?php if($this->getCurrentDirection() == 'desc'): ?>
<img src="<?php echo $this->getSkinUrl('images/i_desc_arrow.gif') ?>" alt="<?php echo $this->__('Set Ascending Direction') ?>" class="v-middle" />
<?php else: ?>
<img src="<?php echo $this->getSkinUrl('images/i_asc_arrow.gif') ?>" alt="<?php echo $this->__('Set Descending Direction') ?>" class="v-middle" />
<?php endif; ?>
</div>
</div>
<?php endif; ?>
can anyone please help me on this? Thanks...
Hello Guys I had the same issue on my Mobileshoppe Template. I tried to add products of a category and it didn't work for me.
In the end the solution was to use as mentioned on the official Mobileshoppe page "readme" file: http://magresponsive.devdemoz.com/readme.html
I used the code where it says: 2) Create cms page (home page) step bellow.
Hope it helps somebody.

magento set Switch Currency Url

I have problem with Currency URL.
Suppose my URL is www.example.com/by_women/?color=black
Now i want to redirect same page after change currency.
Here is my code.
<?php if($this->getCurrencyCount() > 1): ?>
<span>Select Currency:</span>
<select name="custom-currency-selector" id="custom-currency-selector">
<?php foreach ($this->getCurrencies() as $_code => $_name): ?>
<option value="<?php echo $this->getSwitchCurrencyUrl($_code)?>"
<?php if($_code == $this->getCurrentCurrencyCode()): ?>
selected="SELECTED"
<?php endif; ?>>
<?php echo $_code ?>
</option>
<?php endforeach; ?>
</select>
<?php endif;

Replace default "Choose an Option" text in Magento layered navigation dropdown

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>

Magento: Storeview Access

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.

Resources