{"action":"created","issue":{"url":"https://api.github.com/repos/cubecart/v6/issues/1240","repository_url":"https://api.github.com/repos/cubecart/v6","labels_url":"https://api.github.com/repos/cubecart/v6/issues/1240/labels{/name}","comments_url":"https://api.github.com/repos/cubecart/v6/issues/1240/comments","events_url":"https://api.github.com/repos/cubecart/v6/issues/1240/events","html_url":"https://github.com/cubecart/v6/issues/1240","id":177422528,"number":1240,"title":"Admin Create Order Digital Product Bug","user":{"login":"SemperFiWS","id":6945093,"avatar_url":"https://avatars.githubusercontent.com/u/6945093?v=3","gravatar_id":"","url":"https://api.github.com/users/SemperFiWS","html_url":"https://github.com/SemperFiWS","followers_url":"https://api.github.com/users/SemperFiWS/followers","following_url":"https://api.github.com/users/SemperFiWS/following{/other_user}","gists_url":"https://api.github.com/users/SemperFiWS/gists{/gist_id}","starred_url":"https://api.github.com/users/SemperFiWS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SemperFiWS/subscriptions","organizations_url":"https://api.github.com/users/SemperFiWS/orgs","repos_url":"https://api.github.com/users/SemperFiWS/repos","events_url":"https://api.github.com/users/SemperFiWS/events{/privacy}","received_events_url":"https://api.github.com/users/SemperFiWS/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-16T13:14:09Z","updated_at":"2016-12-09T09:09:55Z","closed_at":null,"body":"If you manually create an order with digital products, the link gets created and added to the database.\nBut if you add a digital product to an existing order, the link does not get created and added to the database correctly as the 'cart_order_id' value is not set for the CubeCart_downloads entry.\n\nPotential fix...\n\nFile:\n/classes/order.class.php\nChange This:\n\n```\n    public function createDownload($product_id, $order_inv_id, $customer_id = '') {\n        if(empty($product_id) || empty($order_inv_id)) return false;\n        $this->_order_summary['customer_id'] = $customer_id;\n        return $this->_createDownload($product_id, $order_inv_id);\n    }\n```\n\nTo This:\n\n```\n    public function createDownload($product_id, $order_inv_id, $customer_id = '', $cart_order_id) {\n        if(empty($product_id) || empty($order_inv_id) || empty($cart_order_id)) return false;\n        $this->_order_summary['customer_id'] = $customer_id;\n        return $this->_createDownload($product_id, $order_inv_id, $cart_order_id);\n    }\n```\n\nChange This:\n\n```\n    private function _createDownload($product_id, $order_inv_id) {\n        // Create a reference for a download\n        $accesskey = md5($this->_order_id.$product_id.date('cZ@u').mt_rand());\n\n        $expire = ($GLOBALS['config']->get('config', 'download_expire')>0) ? time() + $GLOBALS['config']->get('config', 'download_expire') : 0;\n\n        $record     = array(\n            'cart_order_id' => (isset($this->_order_summary['cart_order_id'])) ? $this->_order_summary['cart_order_id'] : $this->_order_id , // $this->_order_id,\n            'order_inv_id'  => $order_inv_id,\n            'customer_id' => (isset($this->_order_summary['customer_id'])) ? $this->_order_summary['customer_id'] : $GLOBALS['user']->getId(), // $GLOBALS['user']->getId(),\n            'product_id'    => (int)$product_id,\n            'expire'        => $expire,\n            'accesskey'     => $accesskey,\n        );\n        return $GLOBALS['db']->insert('CubeCart_downloads', $record);\n    }\n```\n\nTo This:\n\n```\n    private function _createDownload($product_id, $order_inv_id, $cart_order_id) {\n        // Create a reference for a download\n        $accesskey = md5($this->_order_id.$product_id.date('cZ@u').mt_rand());\n\n        $expire = ($GLOBALS['config']->get('config', 'download_expire')>0) ? time() + $GLOBALS['config']->get('config', 'download_expire') : 0;\n\n        $record     = array(\n            'cart_order_id' => $cart_order_id,\n            'order_inv_id'  => $order_inv_id,\n            'customer_id' => (isset($this->_order_summary['customer_id'])) ? $this->_order_summary['customer_id'] : $GLOBALS['user']->getId(), // $GLOBALS['user']->getId(),\n            'product_id'    => (int)$product_id,\n            'expire'        => $expire,\n            'accesskey'     => $accesskey,\n        );\n        return $GLOBALS['db']->insert('CubeCart_downloads', $record);\n    }\n```\n\nChange This:\n\n```\n            if ($record['digital'] && !isset($item['certificate'])) {\n                // If digital, create a download code\n                $this->_createDownload($item['id'], (int)$insert_id);\n            }\n```\n\nTo This:\n\n```\n            if ($record['digital'] && !isset($item['certificate'])) {\n                // If digital, create a download code\n                $this->_createDownload($item['id'], (int)$insert_id, $this->_order_id);\n            }\n```\n"},"comment":{"url":"https://api.github.com/repos/cubecart/v6/issues/comments/265967091","html_url":"https://github.com/cubecart/v6/issues/1240#issuecomment-265967091","issue_url":"https://api.github.com/repos/cubecart/v6/issues/1240","id":265967091,"user":{"login":"abrookbanks","id":4520803,"avatar_url":"https://avatars.githubusercontent.com/u/4520803?v=3","gravatar_id":"","url":"https://api.github.com/users/abrookbanks","html_url":"https://github.com/abrookbanks","followers_url":"https://api.github.com/users/abrookbanks/followers","following_url":"https://api.github.com/users/abrookbanks/following{/other_user}","gists_url":"https://api.github.com/users/abrookbanks/gists{/gist_id}","starred_url":"https://api.github.com/users/abrookbanks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abrookbanks/subscriptions","organizations_url":"https://api.github.com/users/abrookbanks/orgs","repos_url":"https://api.github.com/users/abrookbanks/repos","events_url":"https://api.github.com/users/abrookbanks/events{/privacy}","received_events_url":"https://api.github.com/users/abrookbanks/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T09:09:55Z","updated_at":"2016-12-09T09:09:55Z","body":"That still gave me an empty cart_order_id value but I was able to reproduce this issue. I can get it fixed.. "}}
{"actor":{"display_login":"abrookbanks"}}