How can I remove %26 and %3D from url?
-
15-02-2021 - |
문제
When I want to sort products by price (low to high and high to low), my link is not working. Option value is "price&product_list_dir=asc", which encode in "price%26product_list_dir%3Dasc". How can I decode that url?
Here is my code:
<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 selectpicker">
<?php
$url = $_SERVER['REQUEST_URI'];
$path = strstr($url, '?');
?>
<option
<?php if($path == '?product_list_order=price&product_list_dir=desc'): ?>
selected="selected"
<?php endif; ?>
class="high-low" value="price&product_list_dir=desc">
Price - High to low
</option>
<option
<?php if($path == '?product_list_order=price&product_list_dir=asc'): ?>
selected="selected"
<?php endif; ?>
class="low-high" value="<?php /* @escapeNotVerified */ echo __('price&product_list_dir=asc') ?>">
Price - Low to high
</option>
</select></div>
해결책
It's the browser that's encoding the value correctly as expected. Check out https://perishablepress.com/stop-using-unsafe-characters-in-urls/ for safe characters.
In my opinion the best way to do it would be just to set the value to something like "price$product_list_dir!asc" or "price+dir-desc" or just "price_desc" and parse the value of product_list_order in your code. Other options are:
- Split the menu to two drop-down menus (product_list_order and product_list_dir)
- Update the url with javascript when the pulldown selection changes
다른 팁
change this echo __('price&product_list_dir=asc')
to this echo 'price&product_list_dir=asc'
제휴하지 않습니다 magento.stackexchange