Add product option price to Cart page - Opencart? - opencart

How i can add options price to cart.tpl ???
i find option price in product.tpl
<?php foreach ($product['option'] as $option) { ?>
- <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?></small><br />
<?php } ?>
Is there a way to add price to this code?
In the product.tpl and the product.php (controller) we have $option_value['price'] but I don't see this in the cart.php or the cart.tpl. How can we pull this variable into the cart and the checkout page to add it?

In the cart.php search for this line
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
Around the line 226 and you can add the price like this
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value),
'price' => $this->currency->format($option['price'])
);
// var_dump($option); // look more options
Now in the cart.tpl you can show the price
<?php foreach ($product['option'] as $option) { ?>
- <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?>
price: <?php echo $option['price']; ?></small><br />
<?php } ?>

Related

What to Order Status in Opencart My Account page

Thanks for anyone who helps or points me in the right direction.
I want to show Order Status in opencart user (My Account) page. It will show status by status ID. My Pending Status ID:1 and I want to show only Pending Status. Other status will not appear.
<?php echo $order_statuses['order_status_id']; ?>
I put this at account.tpl but result error. Please help me.
Maybe need to modify
*english/account/account.php
controller/account/account.php
template/module/account.tpl*
My Open cart Version 1.5.6.3 with custom Theme.
In account.php you have add this.
$this->load->model('account/order');
$results = $this->model_account_order->getOrders(0, 5);
foreach ($results as $result) {
$product_total = $this->model_account_order->getTotalOrderProductsByOrderId($result['order_id']);
$voucher_total = $this->model_account_order->getTotalOrderVouchersByOrderId($result['order_id']);
$this->data['orders'][] = array(
'order_id' => $result['order_id'],
'name' => $result['firstname'] . ' ' . $result['lastname'],
'status' => $result['status'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'products' => ($product_total + $voucher_total),
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
'href' => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], 'SSL'),
'reorder' => $this->url->link('account/order', 'order_id=' . $result['order_id'], 'SSL')
);
}
In account.tpl add this code
<div id="resent_order" class="recent_order">
<a style="float:right; margin-bottom:15px;" href="<?php echo $manage_order; ?>" class="button">Manage your orders</a><h4>Recent Order</h4>
<ul style="clear:both;">
<?php if( isset($orders) && count($orders > 0 ) ){
foreach ($orders as $order) { ?>
<li>
<div><strong>Order:#</strong><?php echo $order['order_id']; ?></div>
<div><strong>Date:</strong> <?php echo $order['date_added']; ?></div>
<div><strong>Amount:</strong> <?php echo $order['total']; ?></div>
<div><strong>Status:</strong> <?php echo $order['status']; ?></div>
<div class="editPan"><a class="" title="Edit" href="<?php echo $order['href']; ?>">Edit</a></div>
</li>
<?php } ?>
<?php }else{?> <li>You have no recent orders.</li><?php } ?>
</ul>
</div>

Opencart check if product has options

Currently my Opencart site only lets me 'Add to Cart' on the categories page, however if a product has options like 'colour' etc I want it to say 'View Product' instead.
Does anyone know how this can be achieved? I have tried editing the category.php controller to check if a product has options but cannot seem to get it working properly.
Thanks.
Update
So far I have added:
$options = $this->model_catalog_product->getProductOptions($result['product_id']);
Above this array $this->data['products'] = array(); in catalog>controller>product>category.php
This was my attempt to check if a product has options or not. Then I added in catalog>view>theme>mytheme>template>product>category.tpl
<?php if ($product['options']) { ?>
<a href="<?php echo $product['href']; ?>" class="button" />View Product</a>
<?php } else { // EO CATALOGUE MODE ?>
<input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" />
<?php } ?>
But it is not quite cutting the mustard.
You need to add the options to the $products array which is what you are checking in category.tpl:
Look for:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
and add the options as an index to each product array
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'options' => $this->model_catalog_product->getProductOptions($result['product_id']),

How to print ex tax amount on featured, bestseller and related module?

How to print ex-tax amount on featured, bestseller and related module? I tried with $product array but there is no key for ex-tax amount.
Open your bestseller controller file (catalog/controller/module/bestseller.php), and modify this part:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
... by declaring 2 new variables, called price_ex_tax and special_ex_tax in the products array:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'price_ex_tax' => $this->currency->format($result['price']),
'special' => $special,
'special_ex_tax' => $this->currency->format($result['special'],
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
Then you could access the new variables in the bestseller view file (catalog/view/theme/your_theme_name/template/module/bestseller.tpl). Look for this part:
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
</div>
<?php } ?>
... and replace with:
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price'] . "(" . $product['price_ex_tax'] . ")"; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price'] . "(" . $product['price_ex_tax'] . ")"; ?></span> <span class="price-new"><?php echo $product['special'] . "(" . $product['special_ex_tax'] . ")"; ?></span>
<?php } ?>
</div>
<?php } ?>
You could repeat the same steps for the featured module as well (controller file: catalog/controller/module/featured.php - view file: catalog/view/theme/your_theme_name/template/module/featured.tpl). You can find the related products in the product controller file (catalog/controller/product/product.php), and you can display it in the product view file (catalog/view/theme/your_theme_name/product/product.tpl). I hope this helped.
For me it worked when I added this to the controller file: catalog/controller/module/featured.php
Just above the $this->data['products'][] = array( add the following line:
$extax = $this->currency->format($product_info['price']);
Then within the array( add:
'extax' => $extax,
Finally go to catalog/view/theme/your_theme_name/template/module/featured.tpl and add:
<?php echo $product['extax']; ?> where you wish to display the price without tax or
<?php echo $product['price'] . "(" . $product['extax'] . ")"; ?> to show both inc and exc, hope that helps.

opencart how to add manufacturers list like categories list

I just start with Opencart. I need to have list of brands, like llist of catgories. I try so:
<div class="box">
<div class="box-heading"><?php echo "По брендам" ?></div>
<div class="box-content">
<ul class="box-category">
<?php foreach ($manufacturers as $manufacturer) { ?>
<li>
<?php if ($manufacturer['manufacturer_id'] == $manufacturer_id) { ?>
<?php echo $manufacturer['name']; ?>
<?php } else { ?>
<?php echo $manufacturer['name']; ?>
<?php } ?>
<?php if ($manufacturer['children']) { ?>
<ul>
<?php foreach ($manufacturer['children'] as $child) { ?>
<li>
<?php if ($child['manufacturer_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
I add this code in default/template/module/category.tpl file.
I get this error: Notice: Undefined variable: manufacturers in....
How should I do this???
Thanks.
category.tpl is the template for the category controller. Its purpose is to show categories. Try to direct your browser to the http://your.site/index.php?route=product/manufacturer and you will get list of manufacturers. The template is /catalog/view/theme/default/template/product/manufacturer_list.tpl.
Your error is a result of one simple thing: the $manufacturers variable is not defined in ControllerModuleCategory controller (aka category.php). If you want use a variable in a template, you must define it in a relevant controller.
In order to obtain list of manufacturers exactly in the /catalog/view/theme/default/template/module/category.tpl (even if it isn't the purpose of this module), you need be done with few things:
1) In the /catalog/model/catalog/manufacturer.php file (model ModelCatalogManufacturer) add function (this function will help you to obtain the list of manufacturers from the database):
public function getManufacturerByCategory($category_id) {
$query = $this->db->query("SELECT m.*
FROM " . DB_PREFIX . "product p
RIGHT JOIN " . DB_PREFIX . "product_to_category p2c ON
p.product_id = p2c.product_id
LEFT JOIN " . DB_PREFIX . "manufacturer m ON
p.manufacturer_id = m.manufacturer_id
WHERE
p2c.category_id = " . (int)$category_id . " AND
m.manufacturer_id IS NOT NULL
GROUP BY m.manufacturer_id");
return $query->rows;
}
2) In the /catalog/controller/module/category.php file (aka ControllerModuleCategory controller), prior to if (file_exists(DIR_TEMPLATE . $this->config->get('confi... insert the code:
if (isset($this->request->get['path'])) {
$category_id = array_pop($parts);
$this->load->model('catalog/manufacturer');
$this->data['manufacturers'] = $this->model_catalog_manufacturer->getManufacturerByCategory($category_id);
} else {
$this->data['manufacturers'] = array();
}
(Keep in mind $this->data['manufacturers'] from the controller will be available in the template as $manufacturers. $this->data['categories'] will be $categories, $this->data['another_var'] will be $another_var and so on.)
And since the moment you can use your foreach ($manufacturers as $manufacturer) in the category module template (the place where you did try the foreach, when you've received "Undefined variable" error) in order to output list of manufacturers which are applied to products from current category.
Best way is create another module, "manufacturer" module, instead of illegitimate using of category module. But I'm not sure that right now you are ready for this challenge.
BTW, I'm all for shadyyx's link to the Jay Gilford's guide. It is awesome quick start guide for beginners.
I have light solution:
Just add code in Controller:category.php:
$this->load->model('catalog/manufacturer');
$this->data['mans'] = $this->data['manufacturers'] =
$this->model_catalog_manufacturer->getManufacturers();
And View: category.tpl:
<?php
foreach($mans as $mans_value)
{
var_dump($mans_value);
}
?>

Joomla! Virtuemart2 Change product details link to open in new browser window

is there any way to open the product details from category view in a new browser window? The current code for the button is:
<p>
<?php // Product Details Button
echo JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details'));
?>
</p>
I am using Joomla! 2.5.11 and VM 2.0.22a
In addition to title and class, you can pass third parameter to the array:
array('title' => $product->product_name, 'class' => 'product-details', 'target' => '_blank')
I have changed the following code overriding com_virtuemart/views/category/default.php:
<?php // Product Details Button
echo JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details')); ?>
To:
<?php $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id . '&tmpl=component'); ?>
...and for the text link:
<a class="product-details" href="<?php echo $product->link ?>" target="_blank"><?php echo JText::_('COM_VIRTUEMART_PRODUCT_DETAILS') ?></a>