Answer the question
In order to leave comments, you need to log in
How to add the selected option to the alert when ordering a product Opencart 2.3?
Hello, I would like to add a feature to my site. When adding a product with an option, the selected option was shown in the notification (that the product was added to the cart).
Tell me what to fix in the file:
controller\checkout\cart.php
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
}
$option_data = array();
foreach ($product_options as $product_option) {
if ($product_option['required'] && empty($option[$product_option['product_option_id']])) {
$json['error']['option'][$product_option['product_option_id']] = sprintf($this->language->get('error_required'), $product_option['name']);
}
if(!empty($option[$product_option['product_option_id']])){
foreach($product_option as $k => $p_o){
if($k == 'product_option_value'){
foreach($p_o as $v_p_o){
if(is_array($option[$product_option['product_option_id']])){
foreach($option[$product_option['product_option_id']] as $val){
if($val == $v_p_o['product_option_value_id']){
$option_data[] = $v_p_o['name'];
}
}
}else{
if($option[$product_option['product_option_id']] == $v_p_o['product_option_value_id']){
$option_data[] = $v_p_o['name'];
}
}
}
}
}
}
}
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'] . '(' . implode(',',$option_data) . ')', $this->url->link('checkout/cart'));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question