array( 'PRODUCT_SALT', 'input'), 'test_mode' => array('TEST_MODE', 'boolean') ); public function __construct(&$subject, $config) { parent::__construct($subject, $config); } /** * @param object $pack : the hikashop pack object, with the options. * [ pack_id, product_id, quantity, pack_name, pack_data, pack_generator, pack_params ] * @param object $order : the hikashop order object, with all data. * @param int $quantity : the quantity of serials that you generator has to create. * @param array $serials : output array for the generated serials. */ public function generate(&$pack, &$order, $quantity, &$serials) { if(!isset($pack->ultamationapplehswithname)) return; parent::pluginParams($pack->serialwithname); $config = hikaserial::config(); $fastRandom = (int)$config->get('use_fast_random', 0); $salt = $this->plugin_params->salt; if( $this->plugin_params->test_mode ) $salt .= 'TEST'; // Collect the meta data from the product line $myName = ''; $licList = array(); if(!empty($order->cart->products)) { foreach($order->cart->products as $p) { if($p->product_id == $pack->main_product_id) { // Attempt to extract the custom field info if( isset($p->lic_name)) $myName = trim( strtolower( $p->lic_name )); else return false; $licList[] = array( 'myName' => $myName ); } } } else // No products? No serials... { return false; } // Create the serial number foreach( $licList as $lic ) { $serial = "my serial algorithm does its stuff here"; $serials[] = sprintf( "[%s]
%s", $lic['myName'], $serial ); } return true; } public function configurationHead() { return array( 1 => 'salt' ); } public function configurationLine($id = 0, $conf = null) { switch($id) { case 1: if(empty($conf->generator_params->salt)) return 'DefaultProductInfo'; return $conf->generator_params->salt; } return null; } public function onPackGeneratorTypeDisplay(&$values) { parent::listPlugins('serialwithname', $values); } public function onDisplaySerials(&$data, $viewName) { return; } }