Post by jason10 » Wed May 22, 2013 8:34 pm

Hello,

I am using the latest version of Opencart (1.5.5).

In the Invoice, I would like to remove the appearance of Shipping address if the cart only contains a virtual product.

Can you please guide me on how I can do this?

Thanks.

Regards.

Jason

Newbie

Posts

Joined
Wed May 22, 2013 8:31 pm

Post by WilliamBD » Thu May 23, 2013 7:28 pm

Note: This is the quickest solution I could see. But not ideally the best. I think a better approach would be for the shipping value to be passed to the 'ocm_order_product' table reducing the need to load in the product module to find out if a product has shipping. But that would require more code and would break current orders as they would not have a value for it.
----
I assume you mean by 'virtual product' all products have 'no shipping'

I shall offer a code solution first and if this is what you want I shall then put it in to a VQmod for you.

My solution checks all products in the order for shipping and if none of them require shipping then the shipping box on the invoice will disappear.

Step 1 - Change Controller
File: admin->controller->sale->order.php

Part A

After: (Around line 2484)

Code: Select all

$products = $this->model_sale_order->getOrderProducts($order_id);
Add:

Code: Select all

$this->load->model('catalog/product');
$shipping_required = false;
Part B

After: (Around line 2507)

Code: Select all

$product_data[] = array(
						'name'     => $product['name'],
						'model'    => $product['model'],
						'option'   => $option_data,
						'quantity' => $product['quantity'],
						'price'    => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
						'total'    => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value'])
					);
Add:

Code: Select all

$product_info = $this->model_catalog_product->getProduct($product['product_id']);
					
					if($product_info['shipping']) {
						$shipping_required = true;
					}
Part C
Change: (Around line 2535)

Code: Select all

$this->data['orders'][] = array(
					'order_id'	         => $order_id,
					....
					'comment'            => nl2br($order_info['comment'])
				);
To:

Code: Select all

$this->data['orders'][] = array(
					'order_id'	         => $order_id,
					'invoice_no'         => $invoice_no,
					'date_added'         => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
					'store_name'         => $order_info['store_name'],
					'store_url'          => rtrim($order_info['store_url'], '/'),
					'store_address'      => nl2br($store_address),
					'store_email'        => $store_email,
					'store_telephone'    => $store_telephone,
					'store_fax'          => $store_fax,
					'email'              => $order_info['email'],
					'telephone'          => $order_info['telephone'],
					'shipping_required'	 => $shipping_required, // ADDED
					'shipping_address'   => $shipping_address,
					'shipping_method'    => $order_info['shipping_method'],
					'payment_address'    => $payment_address,
					'payment_company_id' => $order_info['payment_company_id'],
					'payment_tax_id'     => $order_info['payment_tax_id'],
					'payment_method'     => $order_info['payment_method'],
					'product'            => $product_data,
					'voucher'            => $voucher_data,
					'total'              => $total_data,
					'comment'            => nl2br($order_info['comment'])
				);
*We just added to the array:

Code: Select all

'shipping_required'	 => $shipping_required,
Step 2 - Update Invoice View

File: admin->view->template->sale->order_invoice.tpl
Change: (Around line 54)

Code: Select all

<td width="50%"><b><?php echo $text_ship_to; ?></b></td>
To:

Code: Select all

<?php if($order['shipping_required']) { ?>
      <td width="50%"><b><?php echo $text_ship_to; ?></b></td>
      <?php } ?>
Change: (Around Line 71)

Code: Select all

      <td><?php echo $order['shipping_address']; ?></td>
To:

Code: Select all

<?php if($order['shipping_required']) { ?>
      <td><?php echo $order['shipping_address']; ?></td>
    <?php } ?>
*Warning: Changing the default template will mean when you update these changes you will lose this. You should copy the default template and then make these changes. I will make a VQmod if requested but again this will break if in an update these files get changed.

*Disclaimer: I hope I have been as clear as possible and helpful. If you are unsure of anything please ask I will be happy to help - I do frequently watch the posts I have posted in previously.

How to change prices across a whole multi-store, with a baseline price for each product:
http://forum.opencart.com/viewtopic.php ... 24#p406793


Active Member

Posts

Joined
Fri Feb 08, 2013 9:33 pm
Who is online

Users browsing this forum: No registered users and 7 guests