/** * Create and return a hash for the download link. * * @return string The requested hash */ public function serialz() { // load the order item and the selectd package options $orderItem = $this->_linkPurchased->getOrderItem(); $productOptions = $orderItem->getProductOptions(); // initialize the subscription runtime $now = Zend_Date::now(); $then = Zend_Date::now()->addMonth(1); // check if custom options are available if (!array_key_exists('options', $productOptions)) { $then->addMonth($this->_getDefaultSubscription()); } else { // iterate over the package's custom options foreach ($productOptions['options'] as $value) { // load the select option itself $option = Mage::getModel('catalog/product_option')->load($value['option_id']); // load the selected option value $value = $option->getValueInstance()->load($value['option_value']); // initialize the subscription model $subscription = Mage::getModel('channel/subscription_type_option'); // try to load the subscription $subscription->loadBySku($value->getSku()); // check if a valid subscription was found if ($subscription->getId() > 0) { // if a subscription was found, use the subscription runtime $then->addMonth($subscription->getValue() - 1); } else { // if not, set the default subscription $then->addMonth($this->_getDefaultSubscription()); } } } // intialize the serialz keys $components['_customerId'] = $this->_number + $this->_getCustomerId(); $components['_productId'] = $this->_number + $this->_getProductId(); $components['_validFrom'] = $now->toString('yyyyMMdd'); $components['_validThru'] = $then->toString('yyyyMMdd'); // initialize and encrypt the serialz $serialCrypted = $this->_encryptor->encrypt(implode('', $components)); // make a more 'look-a-like' serialz ;) for ($i = 0; $i < 64; $i = $i + 8) { $parts[] = strtoupper(substr($serialCrypted, $i, 8)); } // return the serialz return $serialz = implode("-", $parts); }