Magento 2.1 Product Sorting Alter name and price with asc and desc option
File path:
app/design/frontend/<vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/sorter.phtml
I want to alter Sorting options as
Name to Alphabets ASC, Alphabets DESC
Price to Price highest First , Price Lowest First
I have tried below solution :
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetical A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetical Z-A")) ?>
</option>
Issue: When ajax is being called URL created like this -
?product_list_order=price%26product_list_dir%3Ddesc` instead of `?product_list_order=price&product_list_dir=desc
magento-2.1 sorting sort
add a comment |
File path:
app/design/frontend/<vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/sorter.phtml
I want to alter Sorting options as
Name to Alphabets ASC, Alphabets DESC
Price to Price highest First , Price Lowest First
I have tried below solution :
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetical A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetical Z-A")) ?>
</option>
Issue: When ajax is being called URL created like this -
?product_list_order=price%26product_list_dir%3Ddesc` instead of `?product_list_order=price&product_list_dir=desc
magento-2.1 sorting sort
any solution for this?
– Joey
Oct 23 '17 at 6:46
BTW, you cant change that url encoding. but you may able to use jquery/javascript url decoding function and make a redirect. I haven't tried it though.
– Joey
Oct 23 '17 at 10:30
add a comment |
File path:
app/design/frontend/<vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/sorter.phtml
I want to alter Sorting options as
Name to Alphabets ASC, Alphabets DESC
Price to Price highest First , Price Lowest First
I have tried below solution :
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetical A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetical Z-A")) ?>
</option>
Issue: When ajax is being called URL created like this -
?product_list_order=price%26product_list_dir%3Ddesc` instead of `?product_list_order=price&product_list_dir=desc
magento-2.1 sorting sort
File path:
app/design/frontend/<vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/sorter.phtml
I want to alter Sorting options as
Name to Alphabets ASC, Alphabets DESC
Price to Price highest First , Price Lowest First
I have tried below solution :
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetical A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetical Z-A")) ?>
</option>
Issue: When ajax is being called URL created like this -
?product_list_order=price%26product_list_dir%3Ddesc` instead of `?product_list_order=price&product_list_dir=desc
magento-2.1 sorting sort
magento-2.1 sorting sort
edited yesterday
Teja Bhagavan Kollepara
2,93841847
2,93841847
asked Mar 3 '17 at 5:00
Ronak ChauhanRonak Chauhan
4,12511348
4,12511348
any solution for this?
– Joey
Oct 23 '17 at 6:46
BTW, you cant change that url encoding. but you may able to use jquery/javascript url decoding function and make a redirect. I haven't tried it though.
– Joey
Oct 23 '17 at 10:30
add a comment |
any solution for this?
– Joey
Oct 23 '17 at 6:46
BTW, you cant change that url encoding. but you may able to use jquery/javascript url decoding function and make a redirect. I haven't tried it though.
– Joey
Oct 23 '17 at 10:30
any solution for this?
– Joey
Oct 23 '17 at 6:46
any solution for this?
– Joey
Oct 23 '17 at 6:46
BTW, you cant change that url encoding. but you may able to use jquery/javascript url decoding function and make a redirect. I haven't tried it though.
– Joey
Oct 23 '17 at 10:30
BTW, you cant change that url encoding. but you may able to use jquery/javascript url decoding function and make a redirect. I haven't tried it though.
– Joey
Oct 23 '17 at 10:30
add a comment |
2 Answers
2
active
oldest
votes
Here's My solution which works for me
Path(for theme) : /../app/design/frontend//Magento_Catalog/templates/product/list/toolbar/sorter.phtml
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/**
* Product list toolbar
*
* @var $block MagentoCatalogBlockProductProductListToolbar
*/
use MagentoCatalogModelProductProductListToolbar;
?>
<div class="toolbar-sorter sorter">
<label class="sorter-label" for="sorter"><?php /* @escapeNotVerified */ echo __('Sort By') ?></label>
<select id="sorter" data-role="sorter" class="sorter-options">
<option value="<?php /* @escapeNotVerified */ echo 'short_by'; ?>"
<?php if ($block->isOrderCurrent('short_by')): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__("Sorting")) ?>
</option>
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if($_key == "name"):?>
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch Z-A")) ?>
</option>
<?php elseif($_key == "price"):?>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price highest First")) ?>
</option>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price Lowest First")) ?>
</option>
<?php elseif($_key == "position"):?>
<?php else:?>
<option value="<?php /* @escapeNotVerified */ echo $_key; ?>"
<?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__($_order)) ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
Try it if you have any doubt ask me. Thank you.
seems like you hardcoded each url into php, without checking current url. did you test this with some other options? like with some filters(usually in layered navigation)? if this works then, your answer is very good. Anyway did you find any solution for that url encoding problem?
– Joey
Oct 24 '17 at 5:35
Yes, I have tested it and it's working on my live project. @Joey And no I have not find the solution for URL encode yet.
– Ronak Chauhan
Oct 24 '17 at 5:49
add a comment |
I've found a solution for the sort in price ascending/descending.
To do that, I've used jQuery to redirect to url.
First you need to edit sorter.phtml
in <vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/
Replace select
option with your own.
this is mine,
<select id="listpage-sorter">
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if(strtolower($_order) == 'position' ): ?>
<option <?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>>Most Popular</option>
<?php elseif(strtolower($_order) == 'price'): ?>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="desc"): ?>
selected="selected"
<?php endif; ?>>Price High to Low</option>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="asc" ||$block->getCurrentDirection()==""): ?>
selected="selected"
<?php endif; ?>>Price Low to High</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
Then you can add custom js code to redirect for onChange
.
$('#listpage-sorter').on('change', function() {
var sel=this.value;
var url= window.location.href;
if(sel=="Price High to Low")
{
if(url.indexOf('?')==-1)
{
window.location.href = url + "?
product_list_order=price&product_list_dir=desc";
}
like that you can redirect on every possible scenario. I didn't put my complete js code. let me know if you want it.
Hope this helps somebody
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f162712%2fmagento-2-1-product-sorting-alter-name-and-price-with-asc-and-desc-option%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here's My solution which works for me
Path(for theme) : /../app/design/frontend//Magento_Catalog/templates/product/list/toolbar/sorter.phtml
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/**
* Product list toolbar
*
* @var $block MagentoCatalogBlockProductProductListToolbar
*/
use MagentoCatalogModelProductProductListToolbar;
?>
<div class="toolbar-sorter sorter">
<label class="sorter-label" for="sorter"><?php /* @escapeNotVerified */ echo __('Sort By') ?></label>
<select id="sorter" data-role="sorter" class="sorter-options">
<option value="<?php /* @escapeNotVerified */ echo 'short_by'; ?>"
<?php if ($block->isOrderCurrent('short_by')): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__("Sorting")) ?>
</option>
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if($_key == "name"):?>
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch Z-A")) ?>
</option>
<?php elseif($_key == "price"):?>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price highest First")) ?>
</option>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price Lowest First")) ?>
</option>
<?php elseif($_key == "position"):?>
<?php else:?>
<option value="<?php /* @escapeNotVerified */ echo $_key; ?>"
<?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__($_order)) ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
Try it if you have any doubt ask me. Thank you.
seems like you hardcoded each url into php, without checking current url. did you test this with some other options? like with some filters(usually in layered navigation)? if this works then, your answer is very good. Anyway did you find any solution for that url encoding problem?
– Joey
Oct 24 '17 at 5:35
Yes, I have tested it and it's working on my live project. @Joey And no I have not find the solution for URL encode yet.
– Ronak Chauhan
Oct 24 '17 at 5:49
add a comment |
Here's My solution which works for me
Path(for theme) : /../app/design/frontend//Magento_Catalog/templates/product/list/toolbar/sorter.phtml
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/**
* Product list toolbar
*
* @var $block MagentoCatalogBlockProductProductListToolbar
*/
use MagentoCatalogModelProductProductListToolbar;
?>
<div class="toolbar-sorter sorter">
<label class="sorter-label" for="sorter"><?php /* @escapeNotVerified */ echo __('Sort By') ?></label>
<select id="sorter" data-role="sorter" class="sorter-options">
<option value="<?php /* @escapeNotVerified */ echo 'short_by'; ?>"
<?php if ($block->isOrderCurrent('short_by')): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__("Sorting")) ?>
</option>
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if($_key == "name"):?>
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch Z-A")) ?>
</option>
<?php elseif($_key == "price"):?>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price highest First")) ?>
</option>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price Lowest First")) ?>
</option>
<?php elseif($_key == "position"):?>
<?php else:?>
<option value="<?php /* @escapeNotVerified */ echo $_key; ?>"
<?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__($_order)) ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
Try it if you have any doubt ask me. Thank you.
seems like you hardcoded each url into php, without checking current url. did you test this with some other options? like with some filters(usually in layered navigation)? if this works then, your answer is very good. Anyway did you find any solution for that url encoding problem?
– Joey
Oct 24 '17 at 5:35
Yes, I have tested it and it's working on my live project. @Joey And no I have not find the solution for URL encode yet.
– Ronak Chauhan
Oct 24 '17 at 5:49
add a comment |
Here's My solution which works for me
Path(for theme) : /../app/design/frontend//Magento_Catalog/templates/product/list/toolbar/sorter.phtml
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/**
* Product list toolbar
*
* @var $block MagentoCatalogBlockProductProductListToolbar
*/
use MagentoCatalogModelProductProductListToolbar;
?>
<div class="toolbar-sorter sorter">
<label class="sorter-label" for="sorter"><?php /* @escapeNotVerified */ echo __('Sort By') ?></label>
<select id="sorter" data-role="sorter" class="sorter-options">
<option value="<?php /* @escapeNotVerified */ echo 'short_by'; ?>"
<?php if ($block->isOrderCurrent('short_by')): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__("Sorting")) ?>
</option>
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if($_key == "name"):?>
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch Z-A")) ?>
</option>
<?php elseif($_key == "price"):?>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price highest First")) ?>
</option>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price Lowest First")) ?>
</option>
<?php elseif($_key == "position"):?>
<?php else:?>
<option value="<?php /* @escapeNotVerified */ echo $_key; ?>"
<?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__($_order)) ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
Try it if you have any doubt ask me. Thank you.
Here's My solution which works for me
Path(for theme) : /../app/design/frontend//Magento_Catalog/templates/product/list/toolbar/sorter.phtml
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/**
* Product list toolbar
*
* @var $block MagentoCatalogBlockProductProductListToolbar
*/
use MagentoCatalogModelProductProductListToolbar;
?>
<div class="toolbar-sorter sorter">
<label class="sorter-label" for="sorter"><?php /* @escapeNotVerified */ echo __('Sort By') ?></label>
<select id="sorter" data-role="sorter" class="sorter-options">
<option value="<?php /* @escapeNotVerified */ echo 'short_by'; ?>"
<?php if ($block->isOrderCurrent('short_by')): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__("Sorting")) ?>
</option>
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if($_key == "name"):?>
<option value="<?php echo 'name&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch A-Z")) ?>
</option>
<option value="<?php echo 'name&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Alphabetisch Z-A")) ?>
</option>
<?php elseif($_key == "price"):?>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=asc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price highest First")) ?>
</option>
<option value="<?php /* @escapeNotVerified */ echo $_key.'&product_list_dir=desc'; ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
<?php echo $block->escapeHtml(__("Price Lowest First")) ?>
</option>
<?php elseif($_key == "position"):?>
<?php else:?>
<option value="<?php /* @escapeNotVerified */ echo $_key; ?>"
<?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>
>
<?php echo $block->escapeHtml(__($_order)) ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
Try it if you have any doubt ask me. Thank you.
answered Oct 23 '17 at 12:21
Ronak ChauhanRonak Chauhan
4,12511348
4,12511348
seems like you hardcoded each url into php, without checking current url. did you test this with some other options? like with some filters(usually in layered navigation)? if this works then, your answer is very good. Anyway did you find any solution for that url encoding problem?
– Joey
Oct 24 '17 at 5:35
Yes, I have tested it and it's working on my live project. @Joey And no I have not find the solution for URL encode yet.
– Ronak Chauhan
Oct 24 '17 at 5:49
add a comment |
seems like you hardcoded each url into php, without checking current url. did you test this with some other options? like with some filters(usually in layered navigation)? if this works then, your answer is very good. Anyway did you find any solution for that url encoding problem?
– Joey
Oct 24 '17 at 5:35
Yes, I have tested it and it's working on my live project. @Joey And no I have not find the solution for URL encode yet.
– Ronak Chauhan
Oct 24 '17 at 5:49
seems like you hardcoded each url into php, without checking current url. did you test this with some other options? like with some filters(usually in layered navigation)? if this works then, your answer is very good. Anyway did you find any solution for that url encoding problem?
– Joey
Oct 24 '17 at 5:35
seems like you hardcoded each url into php, without checking current url. did you test this with some other options? like with some filters(usually in layered navigation)? if this works then, your answer is very good. Anyway did you find any solution for that url encoding problem?
– Joey
Oct 24 '17 at 5:35
Yes, I have tested it and it's working on my live project. @Joey And no I have not find the solution for URL encode yet.
– Ronak Chauhan
Oct 24 '17 at 5:49
Yes, I have tested it and it's working on my live project. @Joey And no I have not find the solution for URL encode yet.
– Ronak Chauhan
Oct 24 '17 at 5:49
add a comment |
I've found a solution for the sort in price ascending/descending.
To do that, I've used jQuery to redirect to url.
First you need to edit sorter.phtml
in <vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/
Replace select
option with your own.
this is mine,
<select id="listpage-sorter">
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if(strtolower($_order) == 'position' ): ?>
<option <?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>>Most Popular</option>
<?php elseif(strtolower($_order) == 'price'): ?>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="desc"): ?>
selected="selected"
<?php endif; ?>>Price High to Low</option>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="asc" ||$block->getCurrentDirection()==""): ?>
selected="selected"
<?php endif; ?>>Price Low to High</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
Then you can add custom js code to redirect for onChange
.
$('#listpage-sorter').on('change', function() {
var sel=this.value;
var url= window.location.href;
if(sel=="Price High to Low")
{
if(url.indexOf('?')==-1)
{
window.location.href = url + "?
product_list_order=price&product_list_dir=desc";
}
like that you can redirect on every possible scenario. I didn't put my complete js code. let me know if you want it.
Hope this helps somebody
add a comment |
I've found a solution for the sort in price ascending/descending.
To do that, I've used jQuery to redirect to url.
First you need to edit sorter.phtml
in <vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/
Replace select
option with your own.
this is mine,
<select id="listpage-sorter">
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if(strtolower($_order) == 'position' ): ?>
<option <?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>>Most Popular</option>
<?php elseif(strtolower($_order) == 'price'): ?>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="desc"): ?>
selected="selected"
<?php endif; ?>>Price High to Low</option>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="asc" ||$block->getCurrentDirection()==""): ?>
selected="selected"
<?php endif; ?>>Price Low to High</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
Then you can add custom js code to redirect for onChange
.
$('#listpage-sorter').on('change', function() {
var sel=this.value;
var url= window.location.href;
if(sel=="Price High to Low")
{
if(url.indexOf('?')==-1)
{
window.location.href = url + "?
product_list_order=price&product_list_dir=desc";
}
like that you can redirect on every possible scenario. I didn't put my complete js code. let me know if you want it.
Hope this helps somebody
add a comment |
I've found a solution for the sort in price ascending/descending.
To do that, I've used jQuery to redirect to url.
First you need to edit sorter.phtml
in <vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/
Replace select
option with your own.
this is mine,
<select id="listpage-sorter">
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if(strtolower($_order) == 'position' ): ?>
<option <?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>>Most Popular</option>
<?php elseif(strtolower($_order) == 'price'): ?>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="desc"): ?>
selected="selected"
<?php endif; ?>>Price High to Low</option>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="asc" ||$block->getCurrentDirection()==""): ?>
selected="selected"
<?php endif; ?>>Price Low to High</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
Then you can add custom js code to redirect for onChange
.
$('#listpage-sorter').on('change', function() {
var sel=this.value;
var url= window.location.href;
if(sel=="Price High to Low")
{
if(url.indexOf('?')==-1)
{
window.location.href = url + "?
product_list_order=price&product_list_dir=desc";
}
like that you can redirect on every possible scenario. I didn't put my complete js code. let me know if you want it.
Hope this helps somebody
I've found a solution for the sort in price ascending/descending.
To do that, I've used jQuery to redirect to url.
First you need to edit sorter.phtml
in <vendor_name>/<theme_name>/Magento_Catalog/templates/product/list/toolbar/
Replace select
option with your own.
this is mine,
<select id="listpage-sorter">
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
<?php if(strtolower($_order) == 'position' ): ?>
<option <?php if ($block->isOrderCurrent($_key)): ?>
selected="selected"
<?php endif; ?>>Most Popular</option>
<?php elseif(strtolower($_order) == 'price'): ?>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="desc"): ?>
selected="selected"
<?php endif; ?>>Price High to Low</option>
<option <?php if ($block->isOrderCurrent($_key) && $block->getCurrentDirection()=="asc" ||$block->getCurrentDirection()==""): ?>
selected="selected"
<?php endif; ?>>Price Low to High</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
Then you can add custom js code to redirect for onChange
.
$('#listpage-sorter').on('change', function() {
var sel=this.value;
var url= window.location.href;
if(sel=="Price High to Low")
{
if(url.indexOf('?')==-1)
{
window.location.href = url + "?
product_list_order=price&product_list_dir=desc";
}
like that you can redirect on every possible scenario. I didn't put my complete js code. let me know if you want it.
Hope this helps somebody
edited Oct 24 '17 at 5:36
answered Oct 23 '17 at 10:29
JoeyJoey
261217
261217
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f162712%2fmagento-2-1-product-sorting-alter-name-and-price-with-asc-and-desc-option%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
any solution for this?
– Joey
Oct 23 '17 at 6:46
BTW, you cant change that url encoding. but you may able to use jquery/javascript url decoding function and make a redirect. I haven't tried it though.
– Joey
Oct 23 '17 at 10:30