Change default country in OpenCart - opencart2.x

I'm using latest version of OpenCart 2.0.2.0 whenever I go to register page site/index.php?route=account/register it shows United states as default. I know how to change this default country to another default country. Here what I need is, if a user go to register page it will show please select instead of any default country.

It is not option available. but, You can do with modified following code.
Find code: catalog\controller\account\register.php
if (isset($this->request->post['country_id'])) {
$data['country_id'] = $this->request->post['country_id'];
} elseif (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
Remove following code from above code.
else {
$data['country_id'] = $this->config->get('config_country_id');
}

I'm presently working with custom built OpenCart theme, whenever I visit the register page, by default US is showing. If I want to change the default country (US) to another I need to change it via backend. But I would like to display --Please Select -- option on register page country section. Is there any way to change any default country to please select option?

Goto System -> Settings
You can find a list.
click the edit button
then click on the 'Local' Tab
Change your default country from here.

Another option how to do this is going to the template file, and modifying the loop there to not select the current country.
The area where you have:
<select name="country_id" id="input-country" class="form-control">
<option value="">
<?php echo $text_select; ?>
</option>
<?php foreach ($countries as $country) { ?>
<?php if ($country['country_id'] == $country_id) { ?>
<option value="<?php echo $country['country_id']; ?>" selected="selected">
<?php echo $country['name']; ?>
</option>
<?php } else { ?>
<option value="<?php echo $country['country_id']; ?>">
<?php echo $country['name']; ?>
</option>
<?php } ?>
<?php } ?>
</select>
Just remove the part where the script is going to make a select element with "selected", like this, this should be the end code:
<select name="country_id" id="input-country" class="form-control">
<option value="">
<?php echo $text_select; ?>
</option>
<?php foreach ($countries as $country) { ?>
<option value="<?php echo $country['country_id']; ?>">
<?php echo $country['name']; ?>
</option>
<?php } ?>
</select>

Related

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.

Osclass Drop-down selection for city at search insted of category selection

the script is osclasss
This is the original code
?php if ( osc_count_categories() ) { ?>
<div class="cell selector">
<?php osc_categories_select('sCategory', null, __('Select a category', 'bender')) ; ?>
</div>
<div class="cell reset-padding">
<?php } else { ?>
<div class="cell">
<?php } ?>
<button class="ui-button ui-button-big js-submit"><?php _e("Search", 'bender');?></button>
</div>
How can I edit this code to make the user select a city for search not a category ?
Thank you everyone.
I found the solution =)
Thanks to https://stackoverflow.com/users/3465265/key
Just add this code
<?php $aCities = City::newInstance()->listAll(); ?>
<?php if(count($aCities) > 0 ) { ?>
<select name="sCity" id="sCity">
<option value=""><?php _e('Select a city...')?></option>
<?php foreach($aCities as $city) { ?>
<option value="<?php echo $city['s_name'] ; ?>"><?php echo $city['s_name'] ; ?></option>
<?php } ?>
</select>
<?php } ?>

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'); ?>

Magento Insert Sub Category Navigation before breadcrumbs

I am trying to create a sub navigation of the main navigation in Magento and insert it before the breadcrumbs module. So when you navigate to the root catalogue a sub menu of its main child categories appears as a navigation bar above the breadcrumbs but below the root navigation. In the catalogue you click the root category and all main categories under the root category appear as a horizontal navigation bar below it.
I am only able to insert it under the category title but not above the breadcrums module. I created app/design/frontend/theme/template/catalog/navigation/topsub.phtml and entered the following code:
<?php
//get all sub categories for current category
$_category = $this->getCurrentCategory();
$_category_children = $_category->getChildren();
$catIds = explode(',',$_category_children);
$categories = array();
foreach($catIds as $catId) {
$category = Mage::getModel('catalog/category')->load($catId);
$categories[$category->getName()] = array(
'url' => $category->getUrl(),
'img' => $category->getImageUrl()
);
}
?>
<ul class="subnav">
<?php if($category->getIsActive()): ?>
<?php foreach($categories as $name => $data): ?>
<li>
<a href="<?php echo $data['url']; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>">
<img src="<?php echo $data['img']; ?>" />
<div class="category-title"><?php echo $name; ?></div>
</a>
<span>/ </span>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
In my local.xml I have entered
<reference name="mtopsub">
<block type="catalog/navigation" name="topsub" as="topsub" template="catalog/navigation/topsub.phtml"/>
</reference>
In my template file I have called it
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
<?php echo $this->getChildHtml('header') ?>
<div class="main-container col1-layout">
<div class="main">
<div class="msubnav">
<?php echo $this->getChildHtml('mtopsub') ?>
</div>
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
</div>
</div>
<?php echo $this->getChildHtml('footer') ?>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>
Now until this point nothing appears. If I create a static block and enter the following code to it:
<p>{{block type="catalog/navigation" name="catalog.navigation" template="catalog/navigation/topsub.phtml"}}</p>
The sub navigation menu appears as it should but in the wrong position. Instead of appearing above the breadcrumbs module it appears below it and below the Category page Title.
I am sure I am missing something, if anyone can point me in the right direction I would greatly appreciate it.
You're almost there :-)
As you're adding code into the layout template view, you need to modify you layout XML to add your block as a child of the root element:
layout/page.xml (or local.xml)
<reference name="root">
<block type="catalog/navigation" name="mtopsub" as="mtopsub"
template="catalog/navigation/topsub.phtml" />
</reference>
Now when you call:
<?php echo $this->getChildHtml('mtopsub') ?>
inside your layout template, the block will be available and should render correctly.

How do I send parameters to advanced search in Magento?

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>

Resources