rusly
rusly

Reputation: 1522

Retrieve value from new column

I am trying to learn opencart structure, and trying to create a new column under the table product. The new column is "test"

Then I try to retrieve the data under this page index.php?route=checkout/cart (replace price with test column)

catalog\controller\checkout\cart.php
...

$this->data['products'][] = array(
    'key'      => $product['key'],
    'thumb'    => $image,
    'name'     => $product['name'],
    'model'    => $product['model'],
    'option'   => $option_data,
    'quantity' => $product['quantity'],
    'stock'    => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
    'reward'   => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
    'price'    => $product['test'],  //<-- new column
    'total'    => $total,
    'href'     => $this->url->link('product/product', 'product_id=' . $product['product_id']),
    'remove'   => $this->url->link('checkout/cart', 'remove=' . $product['key'])
);

The problem is I'm not getting any output, and I'm not sure how to work with the model. Which query/function is related with this page ?

Upvotes: 0

Views: 76

Answers (1)

shadyyx
shadyyx

Reputation: 16055

The problem is that the $products that are available at cart.php controller are retrieved from the session where they have been stored in previously set structure, so there is no test index and You should get a Notice: undefined index 'test' in .... The $products are retrieved by

foreach ($this->cart->getProducts() as $product) {
    //...
}

See /system/library/cart.php and method getProducts() to understand what I am speaking about.

If You would like to use this at catalog/controller/product/category.php or catalog/controller/product/product.php controllers, the code You are trying will work.

If You replace the price within all product lists and product detail, these controllers:

  • product/
    • category.php
    • manufacturer_info.php
    • product.php
    • search.php
    • special.php
  • module/
    • bestseller.php
    • featured.php
    • latest.php
    • special.php

with Your value, the final price within cart would be Your test value.

Upvotes: 1

Related Questions