This is my code in home.tpl:
I get this error message
Code: Select all
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content">
<div class="top">
<br />
<h1><?php echo $welcome; ?></h1>
</div>
<div class="middle">
<div class="heading"><?php echo $text_latest; ?></div>
<table class="list">
<?php for ($i = 0; $i < sizeof($products); $i = $i + 3) { ?>
<tr>
<?php for ($j = $i; $j < ($i + 3); $j++) { ?>
<td style="width: 25%;"><?php if (isset($products[$j])) { ?>
<div class="productName" id="productName">
<a href="<?php echo $products[$j]['href']; ?>"><?php echo $products[$j]['name']; ?></a>
</div>
<a href="<?php echo $products[$j]['href']; ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" /></a><br />
<?php echo $products[$j]['options']; ?>
<?php if ($display_price) { ?>
<?php if (!$products[$j]['special']) { ?>
<span style="font-family:girlball;color: #000; font-weight: bold;"><?php echo $products[$j]['price']; ?></span><br />
<?php } else { ?>
<span style="font-family:girlball;color: #000; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="font-family:girlball;color: #F00;"><?php echo $products[$j]['special']; ?></span>
<?php } ?>
<?php } ?>
<?php if ($products[$j]['rating']) { ?>
<img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" />
<?php } ?>
<?php } ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div>
<div class="bottom"> </div>
</div>
<?php echo $footer; ?>
I get this error message
Notice: Undefined index: options in public_html/shop/catalog/view/theme/girlball/template/common/home.tpl on line 26
How can I get product options (like color, size, etc) to display on the homepage? I've tried copying from product.tpl and got errors.
I'm not that experienced in PHP programming, but can understand some code.
Please help, thanks!
Nocko
I'm not that experienced in PHP programming, but can understand some code.
Please help, thanks!
Nocko
no sorry it's not going to be that simple at all. options comes up as an undefined index because it's not defined in the controller. Even once you get the options actually pulled which I'm fairly certain that they are not with the getLatestProducts function you wouldn't just echo them you'd have to loop through them cause each product can have multiple options.
OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter
You'll need to grab all the required variables & model calls out of the catalog/controller/product/product.php file and put them in the catalog/controller/common/home.php file before you can use them in the home.tpl file.
http://www.alreadymade.com
Follow me on twitter.com/alreadymade
I put this code in home.php:
when i go to the homepage I just get a plain screen.
Anything missing?
Code: Select all
$this->data['options'] = array();
$options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
foreach ($options as $option) {
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
$option_value_data[] = array(
'option_value_id' => $option_value['product_option_value_id'],
'name' => $option_value['name'],
'price' => (float)$option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : FALSE,
'prefix' => $option_value['prefix']
);
}
$this->data['options'][] = array(
'option_id' => $option['product_option_id'],
'name' => $option['name'],
'option_value' => $option_value_data
);
}
Anything missing?
Here is product.php
Which vars do I pull? Sorry im so PHP newb.
Code: Select all
<?php
class ControllerProductProduct extends Controller {
private $error = array();
public function index() {
$this->language->load('product/product');
$this->document->breadcrumbs = array();
$this->document->breadcrumbs[] = array(
'href' => $this->url->http('common/home'),
'text' => $this->language->get('text_home'),
'separator' => FALSE
);
$this->load->model('tool/seo_url');
$this->load->model('catalog/category');
if (isset($this->request->get['path'])) {
$path = '';
foreach (explode('_', $this->request->get['path']) as $path_id) {
$category_info = $this->model_catalog_category->getCategory($path_id);
if (!$path) {
$path = $path_id;
} else {
$path .= '_' . $path_id;
}
if ($category_info) {
$this->document->breadcrumbs[] = array(
'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $path)),
'text' => $category_info['name'],
'separator' => $this->language->get('text_separator')
);
}
}
}
$this->load->model('catalog/manufacturer');
if (isset($this->request->get['manufacturer_id'])) {
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
if ($manufacturer_info) {
$this->document->breadcrumbs[] = array(
'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/manufacturer&manufacturer_id=' . $this->request->get['manufacturer_id'])),
'text' => $manufacturer_info['name'],
'separator' => $this->language->get('text_separator')
);
}
}
if (isset($this->request->get['keyword'])) {
$url = '';
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
$this->document->breadcrumbs[] = array(
'href' => $this->url->http('product/search&keyword=' . $this->request->get['keyword'] . $url),
'text' => $this->language->get('text_search'),
'separator' => $this->language->get('text_separator')
);
}
$this->load->model('catalog/product');
if (isset($this->request->get['product_id'])) {
$product_id = $this->request->get['product_id'];
} else {
$product_id = 0;
}
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['manufacturer_id'])) {
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
}
if (isset($this->request->get['keyword'])) {
$url .= '&keyword=' . $this->request->get['keyword'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
$this->document->breadcrumbs[] = array(
'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/product' . $url . '&product_id=' . $this->request->get['product_id'])),
'text' => $product_info['name'],
'separator' => $this->language->get('text_separator')
);
$this->document->title = $product_info['name'];
$this->document->description = $product_info['meta_description'];
$this->data['heading_title'] = $product_info['name'];
$this->data['text_enlarge'] = $this->language->get('text_enlarge');
$this->data['text_discount'] = $this->language->get('text_discount');
$this->data['text_options'] = $this->language->get('text_options');
$this->data['text_price'] = $this->language->get('text_price');
$this->data['text_availability'] = $this->language->get('text_availability');
$this->data['text_model'] = $this->language->get('text_model');
$this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
$this->data['text_order_quantity'] = $this->language->get('text_order_quantity');
$this->data['text_price_per_item'] = $this->language->get('text_price_per_item');
$this->data['text_qty'] = $this->language->get('text_qty');
$this->data['text_write'] = $this->language->get('text_write');
$this->data['text_average'] = $this->language->get('text_average');
$this->data['text_no_rating'] = $this->language->get('text_no_rating');
$this->data['text_note'] = $this->language->get('text_note');
$this->data['text_no_images'] = $this->language->get('text_no_images');
$this->data['text_no_related'] = $this->language->get('text_no_related');
$this->data['text_wait'] = $this->language->get('text_wait');
$this->data['entry_name'] = $this->language->get('entry_name');
$this->data['entry_review'] = $this->language->get('entry_review');
$this->data['entry_rating'] = $this->language->get('entry_rating');
$this->data['entry_good'] = $this->language->get('entry_good');
$this->data['entry_bad'] = $this->language->get('entry_bad');
$this->data['entry_captcha'] = $this->language->get('entry_captcha');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->load->model('catalog/review');
$this->data['tab_description'] = $this->language->get('tab_description');
$this->data['tab_image'] = $this->language->get('tab_image');
$this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']));
$this->data['tab_related'] = $this->language->get('tab_related');
$average = $this->model_catalog_review->getAverageRating($this->request->get['product_id']);
$this->data['text_stars'] = sprintf($this->language->get('text_stars'), $average);
$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
$this->data['action'] = $this->url->http('checkout/cart');
$this->data['redirect'] = $this->url->http('product/product' . $url . '&product_id=' . $this->request->get['product_id']);
$this->load->helper('image');
if ($product_info['image']) {
$image = $product_info['image'];
} else {
$image = 'no_image.jpg';
}
$this->data['popup'] = image_resize($image, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
$this->data['thumb'] = image_resize($image, $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
$discount = $this->model_catalog_product->getProductDiscount($this->request->get['product_id']);
if ($discount) {
$this->data['price'] = $this->currency->format($this->tax->calculate($discount, $product_info['tax_class_id'], $this->config->get('config_tax')));
$this->data['special'] = FALSE;
} else {
$this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($this->request->get['product_id']);
if ($special) {
$this->data['special'] = $this->currency->format($this->tax->calculate($special, $product_info['tax_class_id'], $this->config->get('config_tax')));
} else {
$this->data['special'] = FALSE;
}
}
$discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
$this->data['discounts'] = array();
foreach ($discounts as $discount) {
$this->data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
);
}
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock'];
} else {
if ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
}
$this->data['model'] = $product_info['model'];
$this->data['manufacturer'] = $product_info['manufacturer'];
$this->data['manufacturers'] = $this->model_tool_seo_url->rewrite($this->url->http('product/manufacturer&manufacturer_id=' . $product_info['manufacturer_id']));
$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
$this->data['product_id'] = $this->request->get['product_id'];
$this->data['average'] = $average;
$this->data['options'] = array();
$options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
foreach ($options as $option) {
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
$option_value_data[] = array(
'option_value_id' => $option_value['product_option_value_id'],
'name' => $option_value['name'],
'price' => (float)$option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : FALSE,
'prefix' => $option_value['prefix']
);
}
$this->data['options'][] = array(
'option_id' => $option['product_option_id'],
'name' => $option['name'],
'option_value' => $option_value_data
);
}
$this->data['images'] = array();
$results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
foreach ($results as $result) {
$this->data['images'][] = array(
'popup' => image_resize($result['image'] , $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
'thumb' => image_resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
);
}
$this->data['products'] = array();
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
foreach ($results as $result) {
if ($result['image']) {
$image = $result['image'];
} else {
$image = 'no_image.jpg';
}
$rating = $this->model_catalog_review->getAverageRating($result['product_id']);
$special = FALSE;
$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
if ($discount) {
$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
}
}
$this->data['products'][] = array(
'name' => $result['name'],
'model' => $result['model'],
'rating' => $rating,
'stars' => sprintf($this->language->get('text_stars'), $rating),
'thumb' => image_resize($image, $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height')),
'price' => $price,
'special' => $special,
'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id']))
);
}
if (!$this->config->get('config_customer_price')) {
$this->data['display_price'] = TRUE;
} elseif ($this->customer->isLogged()) {
$this->data['display_price'] = TRUE;
} else {
$this->data['display_price'] = FALSE;
}
$this->model_catalog_product->updateViewed($this->request->get['product_id']);
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/product.tpl';
} else {
$this->template = 'default/template/product/product.tpl';
}
$this->children = array(
'common/header',
'common/footer',
'common/column_left',
'common/column_right'
);
$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
} else {
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['manufacturer_id'])) {
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
}
if (isset($this->request->get['keyword'])) {
$url .= '&keyword=' . $this->request->get['keyword'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
$this->document->breadcrumbs[] = array(
'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/product' . $url . '&product_id=' . $product_id)),
'text' => $this->language->get('text_error'),
'separator' => $this->language->get('text_separator')
);
$this->document->title = $this->language->get('text_error');
$this->data['heading_title'] = $this->language->get('text_error');
$this->data['text_error'] = $this->language->get('text_error');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = $this->url->http('common/home');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
} else {
$this->template = 'default/template/error/not_found.tpl';
}
$this->children = array(
'common/header',
'common/footer',
'common/column_left',
'common/column_right'
);
$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
}
}
public function review() {
$this->language->load('product/product');
$this->load->model('catalog/review');
$this->data['text_no_reviews'] = $this->language->get('text_no_reviews');
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
$this->data['reviews'] = array();
$results = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id'], ($page - 1) * 5, 5);
foreach ($results as $result) {
$this->data['reviews'][] = array(
'author' => $result['author'],
'rating' => $result['rating'],
'text' => strip_tags($result['text']),
'stars' => sprintf($this->language->get('text_stars'), $result['rating']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
);
}
$review_total = $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']);
$pagination = new Pagination();
$pagination->total = $review_total;
$pagination->page = $page;
$pagination->limit = 5;
$pagination->text = $this->language->get('text_pagination');
$pagination->url = $this->url->http('product/product/review&product_id=' . $this->request->get['product_id'] . '&page=%s');
$this->data['pagination'] = $pagination->render();
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/review.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/review.tpl';
} else {
$this->template = 'default/template/product/review.tpl';
}
$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
}
public function write() {
$this->language->load('product/product');
$this->load->model('catalog/review');
$json = array();
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_catalog_review->addReview($this->request->get['product_id'], $this->request->post);
$json['success'] = $this->language->get('text_success');
} else {
$json['error'] = $this->error['message'];
}
$this->load->library('json');
$this->response->setOutput(Json::encode($json));
}
public function captcha() {
$this->load->library('captcha');
$captcha = new Captcha();
$this->session->data['captcha'] = $captcha->getCode();
$captcha->showImage();
}
private function validate() {
if ((strlen(utf8_decode($this->request->post['name'])) < 3) || (strlen(utf8_decode($this->request->post['name'])) > 25)) {
$this->error['message'] = $this->language->get('error_name');
}
if ((strlen(utf8_decode($this->request->post['text'])) < 25) || (strlen(utf8_decode($this->request->post['text'])) > 1000)) {
$this->error['message'] = $this->language->get('error_text');
}
if (!$this->request->post['rating']) {
$this->error['message'] = $this->language->get('error_rating');
}
if ($this->session->data['captcha'] != $this->request->post['captcha']) {
$this->error['message'] = $this->language->get('error_captcha');
}
if (!$this->error) {
return TRUE;
} else {
return FALSE;
}
}
}
?>
Which vars do I pull? Sorry im so PHP newb.
You need to load the model before you can call it or use it.
eg. $this->load->model('catalog/product');
eg. $this->load->model('catalog/product');
http://www.alreadymade.com
Follow me on twitter.com/alreadymade
OK, so, I load the model, then call the variable in home.tpl?
I put
$this->data['text_options'] = $this->language->get('text_options');
$this->load->model('catalog/product');
in controller/home.php
and also added
'product/product',
to
$this->children = array(
'common/header',
'common/footer',
'common/column_left',
'common/column_right'
);
in home.tpl, I put
<?php if ($options) { ?>
<b><?php echo $text_options; ?></b><br />
<div style="background: #FFFFCC; border: 1px solid #FFCC33; padding: 10px; margin-top: 2px; margin-bottom: 15px;">
<table style="width: 100%;">
<?php foreach ($options as $option) { ?>
<tr>
<td><?php echo $option['name']; ?>:<br />
<select name="option[<?php echo $option['option_id']; ?>]">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
<?php } ?>
</option>
<?php } ?>
</select></td>
</tr>
<?php } ?>
</table>
<?php } ?>
in the if ($display_price) loop
and i'm getting
I'll keep trying, I think I need to define the options variable. How do I do that? Is there something i'm missing still ?
Thanks
I put
$this->data['text_options'] = $this->language->get('text_options');
$this->load->model('catalog/product');
in controller/home.php
and also added
'product/product',
to
$this->children = array(
'common/header',
'common/footer',
'common/column_left',
'common/column_right'
);
in home.tpl, I put
<?php if ($options) { ?>
<b><?php echo $text_options; ?></b><br />
<div style="background: #FFFFCC; border: 1px solid #FFCC33; padding: 10px; margin-top: 2px; margin-bottom: 15px;">
<table style="width: 100%;">
<?php foreach ($options as $option) { ?>
<tr>
<td><?php echo $option['name']; ?>:<br />
<select name="option[<?php echo $option['option_id']; ?>]">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
<?php } ?>
</option>
<?php } ?>
</select></td>
</tr>
<?php } ?>
</table>
<?php } ?>
in the if ($display_price) loop
and i'm getting
Notice: Undefined variable: options in public_html/shop/catalog/view/theme/girlball/template/common/home.tpl on line 103
I'll keep trying, I think I need to define the options variable. How do I do that? Is there something i'm missing still ?
Thanks
OK, so, I load the model, then call the variable in home.tpl?
I put
$this->data['text_options'] = $this->language->get('text_options');
$this->load->model('catalog/product');
in controller/home.php
and also added
'product/product',
to
$this->children = array(
'common/header',
'common/footer',
'common/column_left',
'common/column_right'
);
in home.tpl, I put
<?php if ($options) { ?>
<b><?php echo $text_options; ?></b><br />
<div style="background: #FFFFCC; border: 1px solid #FFCC33; padding: 10px; margin-top: 2px; margin-bottom: 15px;">
<table style="width: 100%;">
<?php foreach ($options as $option) { ?>
<tr>
<td><?php echo $option['name']; ?>:<br />
<select name="option[<?php echo $option['option_id']; ?>]">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
<?php } ?>
</option>
<?php } ?>
</select></td>
</tr>
<?php } ?>
</table>
<?php } ?>
in the if ($display_price) loop
and i'm getting
Notice: Undefined variable: options in public_html/shop/catalog/view/theme/girlball/template/common/home.tpl on line 103
I'll keep trying, I think I need to define the options variable. How do I do that? Is there something i'm missing still ?
I put
$this->data['text_options'] = $this->language->get('text_options');
$this->load->model('catalog/product');
in controller/home.php
and also added
'product/product',
to
$this->children = array(
'common/header',
'common/footer',
'common/column_left',
'common/column_right'
);
in home.tpl, I put
<?php if ($options) { ?>
<b><?php echo $text_options; ?></b><br />
<div style="background: #FFFFCC; border: 1px solid #FFCC33; padding: 10px; margin-top: 2px; margin-bottom: 15px;">
<table style="width: 100%;">
<?php foreach ($options as $option) { ?>
<tr>
<td><?php echo $option['name']; ?>:<br />
<select name="option[<?php echo $option['option_id']; ?>]">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
<?php } ?>
</option>
<?php } ?>
</select></td>
</tr>
<?php } ?>
</table>
<?php } ?>
in the if ($display_price) loop
and i'm getting
Notice: Undefined variable: options in public_html/shop/catalog/view/theme/girlball/template/common/home.tpl on line 103
I'll keep trying, I think I need to define the options variable. How do I do that? Is there something i'm missing still ?
Who is online
Users browsing this forum: Amazon [Bot] and 97 guests