phpopencart-module

How to add a fuction to copy $URL after creation in the same row of database table


I found the time to experiment with an extension for the opencart and I'm stuck.

I have in model php file the following lines

$cart_options = base64_encode(serialize($cart_products));
$this->db->query("INSERT INTO `". DB_PREFIX ."save_cart`(`options`, `coupon`) VALUES ('$cart_options', '$coupon')");
$db_id = $this->db->getLastId();
$end_url = base64_encode(serialize($db_id));
$url = $this->config->get('config_url').$end_url;

$json = array(
    'text_copy'=> $text_copy,
    'url'=> $url,
);
            
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));

I add in the table a column with "shorturl" name and I want after the &url creation the url copied to the table in the same row. Any idea?

Thanks.


Solution

  • You can update that row after generating url by adding query below the url generation

    $url = $this->config->get('config_url').$end_url;

    $this->db->query("UPDATE ". DB_PREFIX ."save_cart SET shorturl = '”.$this->db->escape($url).”' WHERE id or whatever the primary key = ‘“.(int)$db_id.”’");