To proceed on the bug fixes, followed are expanded solution to get this done along with the other posts above aside from the previous reply which was about a conceptual idea (which I still recommend to be used).
In system/library/cart/cart.php file,
find:
Code: Select all
'download_id' => $download['download_id'],
add below:
Code: Select all
'product_id' => $download['product_id'],
In catalog/model/account/order.php file,
find:
Code: Select all
public function getOrderOptions($order_id, $order_product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'");
return $query->rows;
}
add below:
Code: Select all
public function getOrderDownload($filter_data) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_download` WHERE `download_id` = '" . (int)$filter_data['download_id'] . "', `order_id` = '" . (int)$filter_data['order_id'] . "', `store_id` = '" . (int)$filter_data['store_id'] . "'");
}
In catalog/model/checkout/order.php file,
find all instances of:
Code: Select all
foreach ($product['option'] as $option) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_id = '" . (int)$option['product_option_id'] . "', product_option_value_id = '" . (int)$option['product_option_value_id'] . "', name = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', `type` = '" . $this->db->escape($option['type']) . "'");
}
add below each:
Code: Select all
foreach ($product['download'] as $download) {
if ((int)$download['product_id'] == (int)$product['product_id']) {
this->db->query("INSERT INTO `" . DB_PREFIX . "order_download` SET `download_id` = '" . (int)$download['download_id'] . "', `order_id` = '" . (int)$order_id . "', `store_id` = '" . (int)$data['store_id'] . "'");
}
}
In PHPMyAdmin, on your Opencart database - > SQL tab, execute the following query:
Code: Select all
DROP TABLE IF EXISTS `oc_order_download`;
CREATE TABLE IF NOT EXISTS `oc_order_download` (
`order_download_id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`store_id` int(11) NOT NULL,
`download_id` int(11) NOT NULL,
PRIMARY KEY (`order_download_id`,`order_id`,`store_id`,`download_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
Note: Replace
oc_ with your current database table prefix name if using another prefix. This should completely rectify the issue by adding a separate copy of the order ID along with the store ID and the download ID that originates with the associated product ID during checkout.