Originally Posted by
savage
I would be interested in seeing the code you have so far. So please let me know how I can get a hold of it and if you have made any progress since May.
I'll post this here since others have also asked about it. Regarding Absolute's concerns: that is an issue with any licence scheme. In my case I needed to sell licence codes for third party applications, ie they took care of ensuring that the licence only got used once (they had to do this anyway: the licence was buying access to a service for a period of time, so even the purchaser would have re-used it if they could!)
Anyway, the instructions:
=== Selling licences with ZenCart ===
== Basic concept: ==
~- Add a new table to store licences
~- Buy a product that has licences. During the email confirmation stage update the required licenes to match the new order ID.
~- Add those details to the email
~- Update stock level.
== Comments ==
~- Not written a backend admin bit yet so for time being have to add licences manually to products_licences table
~- Instructions untested. I have done the changes and they work, but then wrote the docs. So the docs may miss something.
~- Email with licence(s) is sent with order confirmation. ''This is not good if payment hasn't been confirmed yet!'' OK for auto CC processing, not good with manual CC processing.
== Details: ==
Create a new table:
Code:
CREATE TABLE `products_licences` (
`licences_id` int(10) unsigned NOT NULL auto_increment,
`products_id` int(10) unsigned NOT NULL default '0',
`products_attributes_id` int(10) unsigned default NULL,
`licences_code` varchar(250) NOT NULL default '',
`orders_id` int(10) unsigned default NULL,
PRIMARY KEY (`licences_id`),
KEY `product_id` (`products_id`,`orders_id`),
KEY `product_attributs_id` (`products_attributes_id`)
) TYPE=MyISAM;
Add the code to includes/classes/order.php, function send_order_email():
Was:
PHP Code:
function send_order_email($zf_insert_id, $zf_mode) {
global $currencies, $order_totals;
Now:
PHP Code:
function send_order_email($zf_insert_id, $zf_mode) {
global $currencies, $order_totals, $db;
// START: MSL - Licences Mod
$licences = array();
//$db->Execute('UPDATE products_licences SET orders_id=NULL'); // DEBUG!!!
$this->licences_html = $this->licences_text = '';
for ($i=0, $n=sizeof($this->products); $i<$n; $i++) {
$db->Execute('UPDATE products_licences SET orders_id='.$zf_insert_id
. ' WHERE products_id='.$this->products[$i]['id']
. ' AND orders_id IS NULL'
. ' LIMIT '.$this->products[$i]['qty']
);
$dbres = $db->Execute('SELECT licences_code FROM products_licences'
. ' WHERE products_id='.$this->products[$i]['id']
. ' AND orders_id='.$zf_insert_id
);
while(!$dbres->EOF) {
$this->licences_html .= '<p>'.$this->products[$i]['name'].':<br><span class=licences_code>'.$dbres->fields['licences_code'].'</span></p>';
$this->licences_text .= $this->products[$i]['name'].":\n".$dbres->fields['licences_code']."\n\n";
$licences[$this->products[$i]['id']][] = $dbres->fields['licences_code'];
$dbres->MoveNext();
}
// Update licences stock level
$dbres = $db->Execute('SELECT count(*) AS count FROM products_licences'
. ' WHERE products_id='.$this->products[$i]['id'].' AND orders_id IS NULL'
);
$db->Execute('UPDATE products SET products_quantity='.$dbres->fields['count'].' WHERE products_id='.$this->products[$i]['id']);
}
// END: MSL - Licences Mod
Was:
PHP Code:
//products area
$email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
EMAIL_SEPARATOR . "\n" .
$this->products_ordered .
EMAIL_SEPARATOR . "\n";
$html_msg['PRODUCTS_TITLE'] = EMAIL_TEXT_PRODUCTS;
$html_msg['PRODUCTS_DETAIL']='<table class="product-details" border="0" width="100%" cellspacing="0" cellpadding="2">' . $this->products_ordered_html . '</table>';
Now:
PHP Code:
//products area
$email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
EMAIL_SEPARATOR . "\n" .
$this->products_ordered .
EMAIL_SEPARATOR . "\n";
$html_msg['PRODUCTS_TITLE'] = EMAIL_TEXT_PRODUCTS;
$html_msg['PRODUCTS_DETAIL']='<table class="product-details" border="0" width="100%" cellspacing="0" cellpadding="2">' . $this->products_ordered_html . '</table>';
// START: MSL - Licences Mod
// Licences Area
if ($this->licences_html) {
$html_msg['PRODUCTS_LICENCES']='<table class="product-details" border="0" width="100%" cellspacing="0" cellpadding="2"><tr><td>' . $this->licences_html . '</td></tr></table>';
$email_order .=
$this->licences_text .
EMAIL_SEPARATOR . "\n";
}
// END: MSL - Licences Mod
== Modify the email template, email/email_template_checkout.html
Was:
Code:
.copyright {border-bottom:0px solid #9a9a9a; padding:5px;}
</style>
Now:
Code:
.copyright {border-bottom:0px solid #9a9a9a; padding:5px;}
.order-licences-area{background-color:#DDDDAA; border:2px #9a9a9a; width:542px; padding:2px; font-size:10px; }
.licences_code{font-weight: bold; font-size: 12px; font-family: monospace;}
</style>
Was:
Code:
<div class="order-detail-area">$ORDER_TOTALS</div>
<div class="comments">$ORDER_COMMENTS</div>
Now:
Code:
<div class="order-detail-area">$ORDER_TOTALS</div>
<div class="order-licences-area">$PRODUCTS_LICENCES</div>
<div class="comments">$ORDER_COMMENTS</div>
Bookmarks