I have a code, but it does not work properly. When the quantity is 0 and Subtract Stock is specified as Yes, the option(s) disappear.
The option(s) remains only when Subtract Stock is specified as No.
Code:
In catalog/controller/product/product.php
First:
Replace: if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
OG: if ($option_value['subtract']) {
Second:
After: $option_value['name'],
Add: 'quantity' => $option_value['quantity'],
In catalog/view/theme/*/template/product/product.tpl
Replace:
<input type="checkbox" name="option[<?php echo $option['product_option_id']; ?>][]" value="<?php echo $option_value['product_option_value_id']; ?>" />
OG:
<input type="checkbox" name="option[<?php echo $option['product_option_id']; ?>][]" value="<?php echo $option_value['product_option_value_id']; ?>" <?php if ($option_value['quantity'] == 0) { ?> disabled <?php } ?> />
In catalog/controller/product/product.php
remove:
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) { and the closing bracket } a couple lines further down.
Now,
add:
'quantity' => $option_value['quantity'],
after:
$product_option_value_data[] = array(
In product.tpl
<input type="checkbox" name="option[<?php echo $option['product_option_id']; ?>][]" value="<?php echo $option_value['product_option_value_id']; ?>" <?php if ($option_value['quantity'] == 0) { echo 'disabled'; } ?> />
Related
Am new in OpenCart MVC, I have page called my_account.tpl. In this page am displaying customer name and tin_number.
If customers want to change their tin_number just fill the TIN Number field and click save, it will update oc_customer tabel.
I tried but data's not update.
Following view, model, and controller codes
View: my_account.tpl
<form action="<?php echo $action;?>" method="POST" enctype="multipart/form-data" class="form-horizontal">
<div class="col-md-9 col-lg-6 col-sm-12">
<?php foreach($customerData as $customer) { ?>
<div class="form-group">
<label>Name:</label>
<input type="text" style="display: none" placeholder="ID" name="id" value="<?php echo $result['tin_number'];?>">
<input type="text" name="name" value="<?php echo $customer['name']; ?>" placeholder="Name" class="form-control" disabled>
</div>
<div class="form-group">
<label>TIN Number:</label>
<input type="text" name="tin_number" value="<?php echo $customer['tin_number']; ?>" placeholder="TIN Number" class="form-control">
</div>
<?php } ?>
<div class="form-group">
<input type="submit" name="save" value="<?php echo 'Save'; ?>" class="btn btn-primary">
</div>
</div>
</form>
Controller: my_account.php
public function edit() {
/*form edit my_account*/
if(isset($_GET['tin_number']))
{
$tin_number=$_GET['tin_number'];
}
$this->load->model('account/customer');
$data['delivery_point']=$this->model_account_customer->getcustomerId($tin_number);
$data['action'] = $this->url->link('account/my_account', '', 'SSL');
if ($this->request->server['REQUEST_METHOD'] == 'POST')
{
$this->model_account_customer->editCustomerTin($this->request->post);
$this->response->redirect($this->url->link('account/home', '', 'SSL'));
echo "<script>javascript: alert('test msgbox')></script>";
}
/*form edit my_account*/
}
Model: my_account.php
public function editCustomerTin($data)
{
$query = $this->db->query("UPDATE " . DB_PREFIX . "customer set tin_number='".$data['tin_number']."' where customer_id=".$data['id']);
}
I got the answer it working in another function see below the coding
controller my_account.php
public function index() {
$this->load->language('account/account');
$this->document->setTitle($this->language->get('heading_title'));
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('Home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('Previous'),
'href' => $this->url->link('common/home', '', 'SSL')
);
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
$data['heading_title'] = $this->language->get('heading_title');
$url = '';
$this->load->model('account/customer');
//$data['customerData']=array();
$results=$this->model_account_customer->getCustomerByTin();
foreach($results as $result)
{
$query1 = $this->db->query("SELECT concat(firstname,' ',lastname) as name,tin_number,invoice_no_overwrite FROM " . DB_PREFIX . "customer where customer_id='".$_COOKIE['customerId']."'");
$customer_name= $query1->row['name'];
$tin_number= $query1->row['tin_number'];
$invoice_no_overwrite= $query1->row['invoice_no_overwrite'];
$data['customerData'][0] = array(
'name' => $customer_name,
'invoice_no_overwrite'=> $invoice_no_overwrite,
'tin_number'=>$tin_number
);
}
//var_dump($data['CustomerData']);
/*form edit my_account*/
if ($this->request->server['REQUEST_METHOD'] == 'POST')
{
$this->model_account_customer->editCustomerTin($this->request->post);
$this->response->redirect($this->url->link('account/my_account', '', 'SSL'));
}
/*form edit my_account*/
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/my_account.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/my_account.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/account/my_account.tpl', $data));
}
}
I don't know how its happen can any one teach me...?
When non-registred user clicking on add to compare then it shows the alert for registration (with message "registration is required"). Please help. I am using magento 1.9. anybody knows answer please share.
this is my list.phtml file
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
//var_dump(Mage::app()->getRequest()->getControllerName());
//get list layout
$currentCat = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getName();
//echo $currentCat;exit;
if ('Retail POS Software' == $currentCat && !$this->getRequest()->isAjax()) {
$displayMode = 'list';
} else {
$displayMode = $this->getMode();
}
//get list layout end
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<?php if (!$this->getRequest()->isAjax()): ?>
<div id="ajax-errors" style="display: none;">
<ul class="messages">
<li class="error-msg">
<ul>
<li><span><?php echo $this->__('An error occurred, please try again later.'); ?></span></li>
</ul>
</li>
</ul>
</div>
<div id="loading" style="display: none; margin-bottom: 10px; text-align: center;">
<img class="v-middle" alt="" src="<?php echo $this->getSkinUrl('images/loader
shopby.gif'); ?>"> <?php echo $this->__('Loading, please wait...'); ?>
</div>
<div id="catalog-listing">
<?php endif; ?>
<div class="category-products">
<div class="toolbar-top">
<?php echo $this->getToolbarHtml() ?>
<?php // List mode
//change $this->getMode() to $displayMode
?>
<div class="yt-products-container clearfix">
<?php if($displayMode!='grid'): ?>
<?php $_iterator = 0; ?>
<ol class="products-list" >
<?php
$count_input_qty = 0;
foreach ($_productCollection as $_product):
$count_input_qty++;
$now = date("Y-m-d");
$newsFrom= substr($_product->getData('news_from_date'),0,10);
$newsTo= substr($_product->getData('news_to_date'),0,10);
$specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
$price = Mage::getModel('catalog/product')->load($_product->getId())->getPrice();
$saleoff= round(($price - $specialprice)/$price*100) ;
?>
<li class="item <?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
<div class="item-inner">
<div class="product-list-left col-lg-4 col-md-4 col-sm-5 col-xs-12">
<div class="product-image">
<a href="<?php echo $_product->getProductUrl() ?>" class="product-img" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,300); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
</a>
<?php if ( $now>=$newsFrom && $now<=$newsTo ){ ?>
<span class="new-product have-ico"><?php echo $this->__('New'); ?></span>
<?php }
if ( $specialprice ){ ?>
<span class="sale-product have-ico"><?php echo $this->__('Sale'); ?></span>
<?php } ?>
</div>
</div>
<div class="product-info col-lg-8 col-md-8 col-sm-7 col-xs-12">
<div class="product-name">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
<?php if( strlen($_helper->productAttribute($_product, $_product->getName(), 'name')) > 100 ){
echo substr($_helper->productAttribute($_product, $_product->getName(), 'name'), 0, 100);
} else {
echo $_helper->productAttribute($_product, $_product->getName(), 'name');
}?>
</a>
</div>
<div class="product-review">
<?php echo $this->getReviewsSummaryHtml($_product, "short", true); ?>
</div>
<div class="product-price">
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
<?php
// Provides extra blocks on which to hang some features for products in the list
// Features providing UI elements targeting this block will display directly below the product name
if ($this->getChild('name.after')) {
$_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
foreach ($_nameAfterChildren as $_nameAfterChildName) {
$_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
$_nameAfterChild->setProduct($_product);
echo $_nameAfterChild->toHtml();
}
}
?>
<?php if($_product->getshort_description()) { ?>
<div class="product-desciption">
<?php echo $_product->getshort_description();?>
</div>
<?php } ?>
<?php /* if($_product->isSaleable()): ?>
<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; */?>
<div class="product-addto-wrap">
<div class="product-addcart">
<?php if($_product->isSaleable()): ?>
<a class="btn-cart" title="<?php echo $this->__('Add to cart') ?>" href="javascript:void(0);" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')">
<?php echo $this->__('Add to cart') ?>
</a>
<?php endif; ?>
</div>
<div class="wishlist-compare">
<?php if ( $this->helper('wishlist')->isAllow() ) : ?>
<a class="link-wishlist" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" title="<?php echo $this->__('Add to Wishlist') ?>">
<?php //echo $this->__('Add to Wishlist') ?>
</a>
<?php endif; ?>
<?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>
<a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>">
<?php //echo $this->__('Add to Compare') ?>
</a>
<?php endif;?>
</div>
</div>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>
<script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
<?php else: ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount();?>
<?php $i=0; foreach ($_productCollection as $_product):?>
<?php
$now = date("Y-m-d H:m:s");
$newsFrom= $_product->getNewsFromDate();
$newsTo= $_product->getNewsToDate();
$specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
$price = Mage::getModel('catalog/product')->load($_product->getId())->getPrice();
$special_from_date = $_product->getSpecialFromDate();
$special_to_date = $_product->getSpecialToDate();
?>
<?php if ( $i++ == 0 ){ ?>
<div class="products-grid">
<div class="row">
<?php } ?>
<div class="item col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="item-inner">
<div class="product-image">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,300); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
</a>
<?php
// Provides extra blocks on which to hang some features for products in the list
// Features providing UI elements targeting this block will display directly below the product name
if ($this->getChild('name.after')) {
$_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
foreach ($_nameAfterChildren as $_nameAfterChildName) {
$_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
$_nameAfterChild->setProduct($_product);
echo $_nameAfterChild->toHtml();
}
}
?>
<?php if ( $now>=$newsFrom && $now<=$newsTo ){ ?>
<span class="new-product have-ico"><?php echo $this->__('New'); ?></span>
<?php }
if ( $specialprice ){ ?>
<span class="sale-product have-ico"><?php echo $this->__('Sale'); ?></span>
<?php } ?>
</div>
<div class="product-info">
<div class="product-name">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
<?php if( strlen($_helper->productAttribute($_product, $_product->getName(), 'name')) > 60 ){
echo substr($_helper->productAttribute($_product, $_product->getName(), 'name'), 0, 60).'...more';
} else {
echo $_helper->productAttribute($_product, $_product->getName(), 'name');
}?>
</a>
</div>
<div class="product-review">
<?php echo $this->getReviewsSummaryHtml($_product, "short", true); ?>
</div>
<div class="product-price">
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
<div class="product-addto-wrap">
<div class="product-addcart">
<?php if($_product->isSaleable()): ?>
<a class="btn-cart" title="<?php echo $this->__('Add to cart') ?>" href="javascript:void(0);" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')">
<?php echo $this->__('Add to Cart') ?>
</a>
<?php else: ?>
<p class="availability out-of-stock">
<span><?php echo $this->__('Out of stock') ?> </span>
</p>
<?php endif; ?>
</div>
<div class="wishlist-compare">
<?php if ( $this->helper('wishlist')->isAllow() ) : ?>
<a class="link-wishlist" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" title="<?php echo $this->__('Add to Wishlist') ?>">
<?php echo $this->__('Add to Wishlist') ?>
</a>
<?php endif; ?>
<?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>
<a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>">
<?php echo $this->__('Add to Compare') ?>
</a>
<?php endif;?>
</div>
</div>
</div>
</div>
</div>
<?php if ( $i == $_collectionSize ){ ?>
</div>
</div>
<?php } ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
</div>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
<?php if (!$this->getRequest()->isAjax()): ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?phpif($this->helper('sm_shopby')->isAjaxEnabled()&&!$this->getRequest()->isAjax()):?>
<script type="text/javascript">
//<![CDATA[
function pushState(data, link, replace) {
var History = window.History;
if ( !History.enabled ) {
return false;
}
if (replace) {
History.replaceState(data, document.title, link);
} else {
History.pushState(data, document.title, link);
}
}
function handleEvent(el, event) {
var url, fullUrl;
if (typeof el === 'string') {
url = el;
} else if (el.tagName.toLowerCase() === 'a') {
url = $(el).readAttribute('href');
} else if (el.tagName.toLowerCase() === 'select') {
url = $(el).getValue();
}
<?php // Add this to query string for full page caching systems ?>
if (url.indexOf('?') != -1) {
fullUrl = url + '&isLayerAjax=1';
} else {
fullUrl = url + '?isLayerAjax=1';
}
$('loading').show();
$('ajax-errors').hide();
pushState(null, url, false);
new Ajax.Request(fullUrl, {
method: 'get',
onSuccess: function(transport) {
if (transport.responseJSON) {
$('catalog-listing').update(transport.responseJSON.listing);
$('layered-navigation').update(transport.responseJSON.layer);
pushState({
listing: transport.responseJSON.listing,
layer: transport.responseJSON.layer
}, url, true);
ajaxListener();
} else {
$('ajax-errors').show();
}
$('loading').hide();
}
});
if (event) {
event.preventDefault();
}
}
function ajaxListener() {
var els;
els = $$('div.pager-wrapper a').concat(
$$('div.sort-by-wrap a'),
$$('div.view-mode-wrap a'),
// $$('div.pager select'),
$$('div.sorter select'),
$$('div.block-layered-nav a')
);
els.each(function(el) {
if (el.tagName.toLowerCase() === 'a') {
$(el).observe('click', function(event) {
handleEvent(this, event);
});
} else if (el.tagName.toLowerCase() === 'select') {
$(el).setAttribute('onchange', '');
$(el).observe('change', function(event) {
handleEvent(this, event);
});
}
});
}
document.observe("dom:loaded", function() {
ajaxListener();
(function(History) {
if ( !History.enabled ) {
return false;
}
pushState({
listing: $('catalog-listing').innerHTML,
layer: $('layered-navigation').innerHTML
}, document.location.href, true);
// Bind to StateChange Event
History.Adapter.bind(window, 'popstate', function(event) {
if (event.type == 'popstate') {
var State = History.getState();
$('catalog-listing').update(State.data.listing);
$('layered-navigation').update(State.data.layer);
ajaxListener();
}
});
})(window.History);
});
//]]>
</script>
<?php endif; ?>
<?php if ($this->getRequest()->isAjax()){ ?>
<?php } ?>
<?php
// Provides a block where additional page components may be attached,primarily good for in-page JavaScript
if ($this->getChild('after')) {
$_afterChildren = $this->getChild('after')->getSortedChildren();
foreach ($_afterChildren as $_afterChildName) {
$_afterChild = $this->getChild('after')->getChild($_afterChildName);
//set product collection on after blocks
$_afterChild->setProductCollection($_productCollection);
echo $_afterChild->toHtml();
}
}
?>
Updated
I have made changes in add to compare button like this,
<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()){
<?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>
<a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>">
<?php //echo $this->__('Add to Compare') ?>
</a>
<?php endif;?>
}
else
{
<?php echo '<script type="text/javascript"> alert("Registration is required for compare product"); </script>?>
}
?>
Got solution after long time.
I have added following code at the place of compare button
<?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>
<?php if(Mage::getSingleton('customer/session')->isLoggedIn()) { ?>
<a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>"></a>
<?php } else { ?>
<a class="link-compare loginToCompare" title="<?php echo $this->__('Add to Compare'); ?>"></a>
<?php } ?>
<?php endif;?>
and added following jquery at the bottom of page for redirection of login page or create account
jQuery(document).ready(function($){
$(".loginToCompare").click(function(){
var r = confirm("You can not compare product without registration please click ok to login or create account!");
if (r == true) {
window.location.href="/customer/account/login/";
}
});
});
this is really working fine for me.
I'm trying to add a new field (programmatically) in the (admin->customer->tab general) customer section of customers called customer number. Everything works as expected but I don't want to get double numbers in the database since the user can enter his own number. Every time a new user gets created from the admin the code looks for the last (highest) customer number and adds +1 to it.
I cannot find a solution for this case:
If the customer already exists (edit mode) it should show a not editable value (readonly)
if registering a new customer the last (highest) customer number should be shown (editable). If the user enters a number that is lower than the highest customer number an error should show up and the highest customer number + 1 should show.
This is the code I have so far
In the controller (getForm):
if (isset($this->error['customer_number'])) {
$data['error_customer_number'] = $this->error['customer_number'];
} else {
$data['error_customer_number'] = '';
}
$data['latest_customer'] = $this->model_sale_customer->getLatestCustomerNumber();
if (isset($this->request->post['customer_number'])) {
$data['customer_number'] = $this->request->post['customer_number'];
} elseif (!empty($customer_info)) {
$data['customer_number'] = $customer_info['customer_number'];
} else {
$data['customer_number'] = '0';
}
In the validation (validateForm):
$data['latest_customer'] = $this->model_sale_customer->getLatestCustomerNumber();
if (isset($this->request->post['customer_number']) && ($this->request->post['customer_number'] <= $data['latest_customer'])) {
$this->error['customer_number'] = $this->language->get('error_customer_number');
}
In my customer_form.tpl I have:
<div class="form-group">
<label class="col-sm-2 control-label" for="input-customer-number"><span data-toggle="tooltip" title="<?php echo $help_customer_number; ?>"> <?php echo $entry_customer_number; ?></span></label>
<div class="col-sm-10">
<?php if (!empty($customer_number) || $customer_number != 0){ ?>
<input type="text" name="customer_number" value="<?php echo $customer_number; ?>" placeholder="<?php echo $entry_customer_number; ?>" id="input-customer-number" class="form-control" />
<?php }else{ ?>
<input type="text" name="customer_number" value="<?php echo $latest_customer + 1; ?>" placeholder="<?php echo $entry_customer_number; ?>" id="input-customer-number" class="form-control" />
<?php if ($error_customer_number) { ?>
<div class="text-danger"><?php echo $error_customer_number; ?></div>
<?php } ?>
<?php } ?>
</div>
</div>
This obviously doesn't work because when editing an existing customer the customer number is always lower than the highest customer number in the system (and thus gives an error). Hope some one can help me out with this! Thanks in advance!
For other who are looking into this I solved my problem myself. Ali's comment made me think. I added a hidden input field so I could check against that. Is it an existing customer or not (has number or not). I only have to check for new customers cause that is an inputfield (existing is readonly and thus not editable). The check is to see if this is a new customer (value 0) - is the posted value < The highest customer number. That's it!
This is the code I have so In the controller (getForm):
if (isset($this->error['customer_number'])) {
$data['error_customer_number'] = $this->error['customer_number'];
} else {
$data['error_customer_number'] = '';
}
if (isset($this->request->post['customer_number']) && (($this->request->post['customer_number'] < $data['latest_customer']) && $this->request->post['existing_customer'] == '0')) {
$this->request->post['customer_number'] = '0';
$data['customer_number'] = '0';
} elseif (isset($this->request->post['customer_number'])) {
$data['customer_number'] = $this->request->post['customer_number'];
} elseif (!empty($customer_info)) {
$data['customer_number'] = $customer_info['customer_number'];
} else {
$data['customer_number'] = '0';
}
if (isset($this->request->post['existing_customer'])) {
$data['existing_customer'] = $this->request->post['existing_customer'];
} else {
$data['existing_customer'] = '0';
}
In the validation (validateForm):
$data['latest_customer'] = $this->model_customer_customer->getLatestCustomerNumber();
if (isset($this->request->post['customer_number']) && (($this->request->post['customer_number'] < $data['latest_customer']) && ($this->request->post['existing_customer'] == '0' || $data['existing_customer'] = '0'))) {
$this->error['customer_number'] = $this->language->get('error_customer_number');
}
In my customer_form.tpl I have:
<div class="form-group">
<label class="col-sm-2 control-label" for="input-customer-number"><span data-toggle="tooltip" title="<?php echo $help_customer_number; ?>"> <?php echo $entry_customer_number; ?></span></label>
<div class="col-sm-10">
<?php if (!empty($customer_number) || $customer_number != 0){ ?>
<input type="text" name="customer_number" value="<?php echo $customer_number; ?>" placeholder="<?php echo $entry_customer_number; ?>" id="input-customer-number" class="form-control" readonly />
<input type="hidden" name="existing_customer" value="1" id="input-existing-customer" class="form-control" />
<?php }else{ ?>
<input type="text" name="customer_number" value="<?php echo $latest_customer + 1; ?>" placeholder="<?php echo $entry_customer_number; ?>" id="input-customer-number" class="form-control" />
<input type="hidden" name="existing_customer" value="0" id="input-existing-customer" class="form-control" />
<?php } ?>
<?php if ($error_customer_number) { ?>
<div class="text-danger"><?php echo $error_customer_number; ?></div>
<?php } ?>
</div>
</div>
I'm trying to customize the "lost password" area in my Wordpress theme, called Enfold. Everything it's ok, so my code sends a link to a "new password introduction" area correctly to users email.
The link is: /new-password/?action=rp&key=TDeJEj7vVmmmJqbd&login=my_username
But when the user clicks on this link and the code redirects him to a "[new password introduction]/[repeat password]" area, the button who execute AJAX code after user write his new password and password confirmation is not responding.
I've added the wp_register_script and wp_enqueue_script to functions.php but I think probably here's my error. I've added it this way:
if(!function_exists('avia_register_frontend_scripts'))
{
if(!is_admin()){
add_action('wp_enqueue_scripts', 'avia_register_frontend_scripts');
}
function avia_register_frontend_scripts()
{
$template_url = get_template_directory_uri();
$child_theme_url = get_stylesheet_directory_uri();
//register js
wp_register_script( 'avia-compat', $template_url.'/js/avia-compat.js', array('jquery'), 1, false ); //needs to be loaded at the top to prevent bugs
wp_register_script( 'avia-default', $template_url.'/js/avia.js', array('jquery'), 1, true );
wp_register_script( 'avia-shortcodes', $template_url.'/js/shortcodes.js', array('jquery'), 1, true );
wp_register_script( 'avia-prettyPhoto', $template_url.'/js/prettyPhoto/js/jquery.prettyPhoto.js', 'jquery', "3.1.5", true);
// wp_register_script( 'wp-mediaelement', $template_url.'/js/mediaelement/mediaelement-and-player.min.js', 'jquery', "1", true);
wp_register_script( 'discount', $template_url.'/js/discount.js', 'javascript', "1", true);
wp_register_script( 'reset_user_pass', $template_url.'/js/reset-user-pass.js','jquery', "1", true );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'avia-compat' );
wp_enqueue_script( 'avia-default' );
wp_enqueue_script( 'avia-shortcodes' );
wp_enqueue_script( 'avia-prettyPhoto' );
wp_enqueue_script( 'wp-mediaelement' );
wp_enqueue_script( 'reset_user_pass' );
Here is the "[new password introduction]/[repeat password]" form code:
<?php
/*Load Scripts for password reset page*/
wp_enqueue_script( 'zxcvbn-async' );
wp_enqueue_script( 'user-profile' );
wp_enqueue_script( 'password-strength-meter' );
wp_enqueue_script( 'user-suggest' );
?>
<form method="post" action="<?php echo get_bloginfo('url') ?>/wp-login.php" id="resetpassform" name="resetpassform">
<input type="hidden" name="login" value="<?php echo $_GET['login'] ?>" autocomplete="off">
<input type="hidden" name="key" value="<?php echo strip_tags($_GET['key']); ?>" />
<p style="margin-bottom:20px" class="description indicator-hint">Your password needs to be at least seven characters. Mixing upper and lower case, numbers and symbols like ! " ? $ % ^ & ) will make it stronger.</p>
<p class="login-username">
<input type="password" tabindex="10" size="20" value="" placeholder="New Password"class="input" id="pass1" name="pass1">
</p>
<p class="login-password">
<input type="password" tabindex="20" size="20" value="" placeholder="Confirm Password" class="input" id="pass2" name="pass2">
</p>
<div class="pass-meter"><div id="pass-strength-result" ><?php _e('Strength indicator'); ?></div></div>
<p class="forgotpass-submit">
<a id="forgot-cancel" href="<?php echo home_url('/signin'); ?>">Cancel</a>
<a id="submitforgotpasswordform" href="javascript:void(0)" style="background-position: 0px 4px;"><input type="submit" tabindex="100" value="Get New Password" id="forgot-submit" name="wp-submit"></a>
</p>
<div class="login-error"><div></div></div>
</form>
Here is the php code to reset pass on validation in my functions.php:
function reset_user_pass(){
parse_str( $_POST['form_values'], $params );
$user = check_password_reset_key($params['key'], $params['login']);
$status='';
// Check if key is valid
if ( is_wp_error($user) ) {
if ( $user->get_error_code() === 'expired_key' ){
$status = 'expiredkey' ;
}
else{
$status = 'invalidkey' ;
}
echo $status;
die;
}
// check if keys match
if ( isset($params['pass1']) && $params['pass1'] != $params['pass2'] ){
$status = 'mismatch';
}else{
// Update the user pass
reset_password($user, $params['pass1']);
$status ='success';
}
echo $status;
die;
}
add_action('wp_ajax_nopriv_reset_user_pass', 'reset_user_pass');
And finally here's the AJAX code who is not responding to submit button:
(function($){
$(document).ready(function() {
// Submit the password reset form via ajax
$( '#resetpassform' ).submit(function(e){
e.preventDefault();
$('.login-error').slideUp();
//check if password fields are empty
if( $('#pass1').val()=='' || $('#pass1').val()=='' ){
return false;
}
var formData= $(this).serialize();
$.ajax({
url: ajaxurl,
type: 'POST',
data: {form_values: formData, action:'reset_user_pass' },
})
.done(function(status) {
switch(status){
case 'expiredkey' :
case 'invalidkey' :
$('.login-error').html('<div>Sorry, the link does not appear to be valid or is expired.</div>').slideDown();
break;
case 'mismatch' :
$('.login-error').html('<div>The passwords do not match.</div>').slideDown();
break;
case 'success' :
$('.login-error').html('<div>Your password has been reset.</div>').slideDown();
break;
default:
console.log(status);
$('.login-error').html('<div>Something went wrong.Please try again </div>').slideDown();
break;
}
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
})
})
})(jQuery)
Thank you so much in advance for your help and time.
Finally the solution was adding the ajax url in a header.php script:
<script type="text/javascript">
var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
</script>
Hope it helps.
I am using the featured module to list products to my homepage. But while the product option works fine in the product details page, it doesnt work well in the homepage(featured module). The option values for the last product is getting repeated to all the product listings. Also add to cart has some problem. Can anyone provide a proper solution to this?
Code is as follows :
controller:
$this->data['products'] = array();
$products = explode(',', $this->config->get('featured_product'));
if (empty($setting['limit'])) {
$setting['limit'] = 5;
}
$products = array_slice($products, 0, (int)$setting['limit']);
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$product_info['special']) {
$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_review_status')) {
$rating = $product_info['rating'];
} else {
$rating = false;
}
$this->data['products'][] = array(
'product_id' => $product_info['product_id'],
'thumb' => $image,
'name' => $product_info['name'],
'price' => $price,
'product_description' => $product_info['product_description'],
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
);
$this->data['options'] = array();
//print_r($this->model_catalog_product->getProductOptions($this->request->get['product_id']));
//die("");
$option=$this->model_catalog_product->getProductOptions($product_id);
//foreach ($this->model_catalog_product->getProductOptions($product_id) as $option) //{
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
$option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$this->data['options'][] = array(
'product_option_id' => $option['product_option_id'],
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'option_value' => $option_value_data,
'required' => $option['required']
);
//}
}
}
view:
<?php foreach ($products as $product) { ?>
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" />
<?php if ($options) { ?>
<div class="options" style="color: #457A33; float: left;line-height: 23px; margin-right: 20px; width:300px;">
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option" style="float:left; width:150px;">
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b><br />
<select name="option[<?php echo $option['product_option_id']; ?>]">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
<br />
What's this
</div>
<?php } ?>
<?php } ?>
The options has to be assigned to the concrete product - so populated and processed before $this->data['products'][] = array(...);:
$this->data['products'] = array();
$products = explode(',', $this->config->get('featured_product'));
if (empty($setting['limit'])) {
$setting['limit'] = 5;
}
$products = array_slice($products, 0, (int)$setting['limit']);
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $setting['image_width'], $setting['image_height']);
} else {
$image = false;
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$product_info['special']) {
$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_review_status')) {
$rating = $product_info['rating'];
} else {
$rating = false;
}
$options = array();
foreach ($this->model_catalog_product->getProductOptions($product_id) as $option) {
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
$option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
}
$options[] = array(
'product_option_id' => $option['product_option_id'],
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'option_value' => $option_value_data,
'required' => $option['required']
);
}
$this->data['products'][] = array(
'product_id' => $product_info['product_id'],
'thumb' => $image,
'name' => $product_info['name'],
'price' => $price,
'product_description' => $product_info['product_description'],
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
'options' => $options,
);
}
Now You should have the options loaded in each product respectively. Just modify your template accordingly:
<?php foreach ($products as $product) { ?>
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" />
<?php if ($product['options']) { ?>
<div class="options" style="color: #457A33; float: left;line-height: 23px; margin-right: 20px; width:300px;">
<?php foreach ($product['options'] as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option" style="float:left; width:150px;">
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b><br />
<select name="option[<?php echo $option['product_option_id']; ?>]">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
<br />
What's this
</div>
<?php } ?>
<?php } ?>