• 17-09-2019, 17:46:11
    #1
    MErhabalar,
    Opencart api ile ürünlerin api olarak çıktısını alıyorum ancak ürün özelliklerini o sayfaya nasıl ekleyebilirim ?

    <?php
    class ControllerApiProduct extends Controller
    {
        public function index()
        {
            $this->load->language('api/cart');
            $this->load->model('catalog/product');
            $this->load->model('tool/image');
            $json = array();
            $json['products'] = array();
            $filter_data = array();
            $results = $this->model_catalog_product->getProducts($filter_data);
            foreach ($results as $result) {
                if ($result['image']) {
                    $image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
                } else {
                    $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
                }
                if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                    $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
                } else {
                    $price = false;
                }
                if ((float) $result['special']) {
                    $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
                } else {
                    $special = false;
                }
                if ($this->config->get('config_tax')) {
                    $tax = $this->currency->format((float) $result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
                } else {
                    $tax = false;
                }
                if ($this->config->get('config_review_status')) {
                    $rating = (int) $result['rating'];
                } else {
                    $rating = false;
                }
                $data['products'][] = array(
                    'product_id' => $result['product_id'],
                    'thumb' => $image,
                    'name' => $result['name'],
                    'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
                    'price' => $price,
                    'special' => $special,
                    'tax' => $tax,
                    'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
                    'rating' => $result['rating'],
                    'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
                );
            }
            $json['products'] = $data['products'];
            $this->response->addHeader('Content-Type: application/json');
            $this->response->setOutput(json_encode($json));
        }
    }
    Şu an bu kodu kullanıyorum çıktı sayfası için
    Renk, ölçü vb. bilgileri buraya nasıl yazdırabilirim ?
  • 17-09-2019, 19:44:33
    #2
    <?php
    class ControllerApiProduct extends Controller
    {
    public function index()
    {
    $this->load->language('api/cart');
    $this->load->model('catalog/product');
    $this->load->model('tool/image');
    $json = array();
    $json['products'] = array();
    $filter_data = array();
    $results = $this->model_catalog_product->getProducts($filter_data);
    foreach ($results as $result) {
    if ($result['image']) {
    $image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
    } else {
    $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
    }
    if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
    $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
    } else {
    $price = false;
    }
    if ((float) $result['special']) {
    $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
    } else {
    $special = false;
    }
    if ($this->config->get('config_tax')) {
    $tax = $this->currency->format((float) $result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
    } else {
    $tax = false;
    }
    if ($this->config->get('config_review_status')) {
    $rating = (int) $result['rating'];
    } else {
    $rating = false;
    }
    
    
                $data['options'] = array();
    
                foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
                    $product_option_value_data = array();
    
                    foreach ($option['product_option_value'] as $option_value) {
                        
                        if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
                            if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
                                $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax') ? 'P' : false), $this->session->data['currency']);
                            } else {
                                $price = false;
                            }
    
                            $product_option_value_data[] = array(
                                'product_option_value_id' => $option_value['product_option_value_id'],
                                'option_value_id' => $option_value['option_value_id'],
                                'name' => $option_value['name'],
                                'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
                                'price' => $price,
                                'price_prefix' => $option_value['price_prefix']
                            );
                        }
                    }
    
                    $data['options'][] = array(
                        'product_option_id' => $option['product_option_id'],
                        'product_option_value' => $product_option_value_data,
                        'option_id' => $option['option_id'],
                        'name' => $option['name'],
                        'type' => $option['type'],
                        'value' => $option['value'],
                        'required' => $option['required']
                    );
                }
    
    
    $data['products'][] = array(
    'product_id' => $result['product_id'],
    'products_option' => $data['options'],//yeni eklenen
    'thumb' => $image,
    'name' => $result['name'],
    'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
    'price' => $price,
    'special' => $special,
    'tax' => $tax,
    'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
    'rating' => $result['rating'],
    'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
    );
    }
    $json['products'] = $data['products'];
    $this->response->addHeader('Content-Type: application/json');
    $this->response->setOutput(json_encode($json));
    }
    }