Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function _beforeSave()
- {
- parent::_beforeSave();
- $hlp = Mage::helper('ugiftcert');
- if ($hlp->isPattern($this->getData('cert_number'))) {
- $pattern = $this->getData('cert_number');
- $dup = Mage::getModel('ugiftcert/cert');
- $i = 0;
- while ($i++<200) { // 10 times can't find free slot - a problem
- $num = $hlp->processRandomPattern($pattern);
- $dup->load($num, 'cert_number');
- if (!$dup->getCertId()) {
- break;
- }
- $num = false;
- }
- if ($num===false) {
- throw new Mage_Core_Exception('Exceeded maximum retries to find available random certificate number');
- }
- $this->setData('cert_number', $num);
- }
- if (Mage::getStoreConfig('ugiftcert/default/use_pin') && $hlp->isPattern($this->getData('pin'))) {
- $this->setData('pin', $hlp->processRandomPattern($this->getData('pin')));
- }
- if ($date = $this->getExpireAt()) {
- $locale = Mage::app()->getLocale();
- $format = $locale->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
- $dateObject = $locale->date($date, $format, null, false);
- $this->setExpireAt($dateObject->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
- } else {
- $this->setExpireAt(null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement