How do I send parameters to advanced search in Magento? - search

I have the following search form in Magento:
<form action="catalogsearch/advanced/result/" method="get" id="form-validate">
<input name="name" type="text" id="textfield" value="" />
<select name="platform" id="select">
<option value='6'>XBox</option>
<option value='5'>XBox 360</option>
</select>
<input type="submit" name="button" id="button" value="Search" />
</form>
Please note the “platform” field is a product attribute. While "name" field is product name.
No matter what I search, the results page always say “No items were found using the following search criteria”
I can see that two parameters are being passed:
result/?name=Logitech&platform;=5
Even if I change this to following, it doesn’t work:
result/?name=Logitech&platform;=XBox
Changing this to doesn’t work either:
result/?name=Logitech
The product is there in database I have checked. What am I doing wrong?
Thanks

This is quick a cut/paste from a code I used for a client whose attribute was a dropdown-type attribute.
Your attribute code must be "platform" for this to work.
<?
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'platform');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$_platforms = $attribute->getSource()->getAllOptions(false);
?>
<select onchange="location.href='<?php echo $this->getUrl('catalogsearch/advanced/result') . '?platform[]='; ?>'+this.value;">
<option selected><?php echo $this->__('Search by platform') ?></option>
<?php foreach($_platforms as $_platform) : ?>
<option value="<?php echo $_platform['value']; ?>"><?php echo $_platform['label']; ?></option>
<?php endforeach; ?>
</select>

Related

Inserting argument with Jekyll

I am trying to insert the attribute "selected" into the first option (volvo) with Jekyll without writing anything in the form.
I guess I should do it with capture but don't get how it works for passing attributes.
cars.html
<html>
<body>
...
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
...
</body>
</html>

Setting echo $_GET inside of a form

I have the following set up below.
My issue is I'm not sure how to convert an inline echo $_GET. Is it just the same as {{ fn( echo $_GET['units'] === 'Miles' ? 'selected' : null ) }}??
<form method="get" action="{{ post.link }}">
<div>
<span>Find a Store within</span>
<input name="proximity" type="number" placeholder="15" value="<?php echo $_GET['proximity'] ?>" />
<select name="units">
<option value="Miles" <?php echo $_GET['units'] === 'Miles' ? 'selected' : null; ?>>Miles</option>
<option value="K" <?php echo $_GET['units'] === 'K' ? 'selected' : null; ?>>Km</option>
</select>
<span>from</span>
<input name="origin" type="text" placeholder="Your Address" value="<?php echo $_GET['origin'] ?>" />
</div>
<div>
<input type="submit" value="Search" />
Reset
</div>
</form>
Thanks to #DarkBee for pointing the above out: Passing PHP global variables via Twig/Timber
To access $_POST variables, use this:
{{ request.post.name_of_var }}
To access $_GET variables, use this:
{{ request.get.name_of_var }}
So that would make this:
<input name="origin" type="text" placeholder="Your Address" value="<?php echo $_GET['origin'] ?>" />
Be this:
<input name="origin" type="text" placeholder="Your Address" value="{{ request.get.origin}}

ASP.Net validation not fireing for hidden fileds

I have 3 required fields on my page and 2 of them are hidden. The hidden fields values are filled by jQuery based off the selection of dropdown lists. If I just leave everything blank so that none of the fields are every filled in and hit the submit button the #Html.ValidationSummery() only lists an error for the 1 visible field. How can I get it to show errors when the hidden fields don't have a value as well?
The code for my hidden fields:
<li>
<label for="SelectedProjects">Selected Projects:</label>
<select size="1" id="SelectedProjects" name="SelectedProjects" multiple="multiple"></select> <button class="removeButton" data-codetype="Project" type="button">-</button>
#Html.EditorFor(m => m.SelectedProjectCodes)
</li>
<li>
<label for="SelectedTasks">Selected Tasks:</label>
<select size="1" multiple="multiple" id="SelectedTasks" name="SelectedTasks"></select> <button class="removeButton" data-codetype="Task" type="button">-</button>
#Html.EditorFor(m => m.SelectedTaskCodes)
</li>
The HTML rendered:
<li>
<label for="SelectedProjects">Selected Projects:</label>
<select size="1" id="SelectedProjects" name="SelectedProjects" multiple="multiple"></select> <button class="removeButton" data-codetype="Project" type="button">-</button>
<input data-val="true" data-val-required="The SelectedProjectCodes field is required." id="SelectedProjectCodes" name="SelectedProjectCodes" type="hidden" value="" />
</li>
<li>
<label for="SelectedTasks">Selected Tasks:</label>
<select size="1" multiple="multiple" id="SelectedTasks" name="SelectedTasks"></select> <button class="removeButton" data-codetype="Task" type="button">-</button>
<input data-val="true" data-val-required="The SelectedTaskCodes field is required." id="SelectedTaskCodes" name="SelectedTaskCodes" type="hidden" value="" />
</li>
The properties in the ViewModel backing it:
[HiddenInput(DisplayValue = false), Required]
public string SelectedProjectCodes { get; set; }
[HiddenInput(DisplayValue = false), Required]
public string SelectedTaskCodes { get; set; }
By default jQuery validation (which is what MVC uses) ignores hidden fields. You can adjust this by changing the default setting when the page loads. One way might be to add an class to the hidden fields to force them to be validated.
<li>
<label for="SelectedProjects">Selected Projects:</label>
<select size="1" id="SelectedProjects" name="SelectedProjects" multiple="multiple"></select> <button class="removeButton" data-codetype="Project" type="button">-</button>
<input class="force-validation" data-val="true" data-val-required="The SelectedProjectCodes field is required." id="SelectedProjectCodes" name="SelectedProjectCodes" type="hidden" value=""/>
</li>
the the javacript to change the defaults would look like this
jQuery.validator.setDefaults({
ignore: ":hidden:not(.force-validation)"
});

Opencart2 restrict user group to change stock in edit product page

Is it possible to disallow access to quantity fields in opencart 2 admin product edit (general quantity and option values quantity)?
I want only the admin to be able to change the quantities.
Can i use something like if user_group_id!=1 (not admin) echo "readonly" to the input field of quantity?
I've tried for test to add a readonly, without if , to the input field in admin/view/template/catalog/product_form.tpl but nothing changed to the code as seen in view source.
Which file can i edit ?
Thank you,
Try following code. I think this will help you
admin/controller/catelog/product.php
Add following code before : if (!isset($this->request->get['product_id'])) {
// load user group model
$this->load->model('user/user');
$user_details = $this->model_user_user->getUser($this->session->data['user_id']);
$data['user_group_id'] = $user_details['user_group_id'];
admin/view/template/catalog/product_form.tpl
replace quantity html to following code
<div class="form-group">
<label class="col-sm-2 control-label" for="input-quantity"><?php echo $entry_quantity; ?></label>
<div class="col-sm-10">
<?php if(isset($user_group_id) && $user_group_id == 1) { ?>
<input type="text" name="quantity" value="<?php echo $quantity; ?>" placeholder="<?php echo $entry_quantity; ?>" id="input-quantity" class="form-control" />
<?php } else {
echo $quantity;
} ?>
</div>
</div>
Note : This is based on admin user group.

Magento product view page quantity box always adds 1 to the cart issue

I'm developing a magento store and in the product view page/details page i have added a jquery quantity box.It works fine.But when click on the add to cart button always add "1" to the cart although i changed the quantity amount in the quantity box.I searched this issue in every place possible sites.But still no luck.And i have placed the input quantity box at the correct place.That means inside the form.I can't figure it out the issue.Hope a help.And my Magento version is 1.8.
This works with form tag... you can edit your default/theme/template/catalog/product/view/addtocart.phtml like this.
<form>
<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<label class="qty_label" for="qty"><?php echo $this->__('Quantity') ?>:</label>
<div class="qty_pan">
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>
<?php endif; ?>
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
<?php endif; ?>
</form>
From Magento version 1.8 onwards, you need to add formkey value inside your form.
If formkey is not set in the form, then always the default qty 1 will be added to cart.
Also, if you try to update the qty from cart page, it will not get updated and will always be set to 1.
To solve this issue, add the following code inside the <form > tag:
<?php echo $this->getBlockHtml('formkey'); ?>
This code is similar to:
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
Porduct View Page
app/design/frontend/YOUR_PACKAGE/YOUR_THEME/catalog/product/view.phtml
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
<?php echo $this->getBlockHtml('formkey'); ?>
Shopping Cart Page
app/design/frontend/YOUR_PACKAGE/YOUR_THEME/checkout/cart.phtml
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
<?php echo $this->getBlockHtml('formkey'); ?>

Resources