I originally posted this to the concepts forum when I was trying to make it work. But after reading it seems like this is more where it belongs.
The only thing that is not working for me is a warning on the cart page when someone enters a model# that does not exist. This is not a functional problem. It just fails to add the item if it isn't found. If someone sees what I need to fix there please let me know.
okies the changes...
I had to add a GetProductByModel function to the product model I just copied the GetProduct method and edited it for the alternate field.
catalog/model/catalog/product.php
Code: Select all
public function getProductByModel($model) {
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.model = '" . $model . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");
return $query->row;
}
I edited the section that called the error/not_found template to add an empty_basket template based on this thread . The thread explains finding the template file to replace. Though I changed their text to allow me to put the empty cart template with the regular template in order to keep the cart stuff together.
Code: Select all
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/empty_basket.tpl')) {
$this->template = $this->config->get('config_template') . '/template/checkout/empty_basket.tpl';
} else {
$this->template = 'default/template/error/not_found.tpl';
}
Code: Select all
if(isset($this->request->post['model'])) {
$this->load->model('catalog/product');
$part_number = $this->request->post['model'];
$pullproduct = $this->model_catalog_product->GetProductByModel($part_number);
if(!$pullproduct) {
$this->data['noproduct'] = $this->language->get('error_nsp');
$this->data['error_warning'] = $this->language->get('error_nsp');
}
else {
$product_id = $pullproduct['product_id'];
$qoh = $pullproduct["quantity"];
if (!$this->request->post['quant']) { $qadd = "1"; }
else {$qadd = $this->request->post['quant']; }
if($this->request->post['quant'] > $qoh) {
$this->data['error_warning'] = $this->language->get('error_stock');
}
$this->cart->add($product_id, $qadd, "");
}
}
Code: Select all
$_['error_nsp'] = 'Part Number Not found. This item is either not in our online database or you made an error when entering the part number.';
template/checkout/empty_basket.tpl (I have been a bit loose with the open cart template so you may need to play with the html.
You may notice that I use "quant" instead of "quantity" in the form. The default cart.php controller uses quantity as the hook to add products under the current system, so I used "quant" to keep my insert separate.
Code: Select all
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div class="content">
<div class="top">
<h1>Your Cart is currently Empty</h1>
<p>You can start your order here by adding items using Part Numbers from your Dixie International Catalog.</p>
<?php if(isset($noproduct)) {?>
<p class="warning"><?php echo $noproduct; ?></p>
<?php } ?>
</div>
<div class="middle">
<form name-"addbymodel" action="index.php?route=checkout/cart" method="post" enctype="multipart/form-data">
<table>
<tr>
<th align="center">Dixie Number</th>
<th align ="center">Quantity</th>
</tr>
<tr>
<input type="hidden" name="route" value="checkout/cart">
<td><input type="text" name="model" size="7" /></td>
<td><input type="text" name="quant" size="3" /></td>
<td align="left">
<input type="image" name="submit" src="image/button_add.png" value="add">
</tr>
</table>
</form>
</div>
<div class="bottom">
</div>
</div>
<?php echo $footer; ?>
Code: Select all
<tr>
<td></td>
<td></td>
<td><b>Add Item By Part Number</b>
<br>Enter Part Number and Quantity then click update below)
</td>
<td><input type="text" name="model" size="7" /></td>
<td><input type="text" name="quant" size="3" /></td>
<td></td>
<td></td>
</tr>
I am pretty sure that is everything. Again If you happen to have a solution to my warnings issue that would be great. When I figure it out I will edit things here.