Post by epo » Sat Feb 26, 2011 1:03 am

The object of this mod was to make it so that customers could add items to their cart by part number (the model field). The store this is for is a distributor and a lot of their customers assemble orders using old catalogs. This way they can come to the site and add their order into the existing cart. (I am on 1.4.9.3)

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;
	}
Most of the rest of the changes were in controller/checkout/cart.php

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';
         }
I inserted the below into the POST section of the cart controller, around line 65 under the "if" statement for quantity. The quantity statement was used as a basis for this. The if(!$pullproduct) is where I am having issues generating a variable to display. It works fine when the cart is empty, but when it has items the error does not show up. There is some duplication in the code there because I am still expierimenting.

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, "");					
						}
		
		}
in the catalog/language/english/checkout/cart.php I added

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.';	
I added an empty cart template to allow me to have the form appear so customers can enter an order.
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; ?>
In the original cart.tpl I insert a row into the original form. This works with the existing form and integrates smoothly.

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 had added my little $noproduct warning into the page, but it is not working so I did not add it here.

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.

epo
Newbie

Posts

Joined
Tue Feb 22, 2011 10:07 am
Who is online

Users browsing this forum: No registered users and 2 guests