protected function _addSarpInfo($buyRequest, $product)
 {
     $Period = Mage::getModel('sarp/period');
     /* We should add custom options that doesnt exist */
     if ($buyRequest->getAwSarpSubscriptionType()) {
         if ($Period->load($buyRequest->getAwSarpSubscriptionType())->getId()) {
             $product->addCustomOption('aw_sarp_subscription_type', $Period->getId());
         }
     }
     if (!is_null($buyRequest->getAwSarpSubscriptionStart()) && $Period->getId()) {
         $start = $buyRequest->getAwSarpSubscriptionStart();
         if (!empty($start)) {
             $date = new Zend_Date($start, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
         } else {
             $date = $Period->getNearestAvailableDay();
         }
         // Check date
         // Never check if start date
         //$performDateCompare = !!Mage::getSingleton('customer/session')->getCustomer()->getId();
         $performDateCompare = !AW_Sarp_Model_Cron::$isCronSession;
         $today = new Zend_Date();
         if (!$this->isVirtual($product)) {
             $today->addDayOfYear($Period->getPaymentOffset());
         }
         if ($performDateCompare && ($date->compare($today, Zend_Date::DATE_SHORT) < 0 || !$Period->isAllowedDate($date, $product))) {
             $date = $Period->getNearestAvailableDay();
         }
     } else {
         $date = Mage::app()->getLocale()->date();
     }
     $product->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd'));
 }
 /**
  * Prepare product and its configuration to be added to some products list.
  * Perform standard preparation process and then add Configurable specific options.
  *
  * @param Varien_Object $buyRequest
  * @param Mage_Catalog_Model_Product $product
  * @param string $processMode
  * @return array|string
  */
 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
 {
     if (!$product->getAwSarpEnabled()) {
         return;
     }
     Mage::getModel('sarp/product_type_default')->checkPeriod($product, $buyRequest);
     $Period = Mage::getModel('sarp/period');
     /* We should add custom options that doesn't exist */
     if ($buyRequest->getAwSarpSubscriptionType()) {
         if ($Period->load($buyRequest->getAwSarpSubscriptionType())->getId()) {
             $product->addCustomOption('aw_sarp_subscription_type', $Period->getId());
         }
     }
     if ((empty($options['aw_sarp_subscription_start']['month']) || empty($options['aw_sarp_subscription_start']['day']) || empty($options['aw_sarp_subscription_start']['year'])) && $buyRequest->getAwSarpSubscriptionType() != AW_Sarp_Model_Period::PERIOD_TYPE_NONE) {
         $date = new Zend_Date();
         $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
     }
     if (isset($options['aw_sarp_subscription_start']) && is_array($options['aw_sarp_subscription_start']) && $buyRequest->getAwSarpSubscriptionType() != AW_Sarp_Model_Period::PERIOD_TYPE_NONE && !empty($options['aw_sarp_subscription_start']['month']) && !empty($options['aw_sarp_subscription_start']['day']) && !empty($options['aw_sarp_subscription_start']['year'])) {
         $subscriptionStart = $options['aw_sarp_subscription_start'];
         $date = new Zend_Date();
         $date->setMinute(0)->setHour(0)->setSecond(0)->setDay($subscriptionStart['day'])->setMonth($subscriptionStart['month'])->setYear($subscriptionStart['year']);
         $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
     }
     if (!is_null($buyRequest->getAwSarpSubscriptionStart()) && $Period->getId()) {
         $start = $buyRequest->getAwSarpSubscriptionStart();
         if (!empty($start)) {
             $date = new Zend_Date($start, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
         } else {
             $date = $Period->getNearestAvailableDay();
         }
         $performDateCompare = !AW_Sarp_Model_Cron::$isCronSession;
         $today = new Zend_Date();
         if (!$this->isVirtual($product)) {
             $today->addDayOfYear($Period->getPaymentOffset());
         }
         if ($performDateCompare && ($date->compare($today, Zend_Date::DATE_SHORT) < 0 || !$Period->isAllowedDate($date, $product))) {
             $date = $Period->getNearestAvailableDay();
         }
     } else {
         $date = Mage::app()->getLocale()->date();
     }
     $product->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd'));
     $_result = parent::_prepareProduct($buyRequest, $product, $processMode);
     if (is_array($_result)) {
         if ($buyRequest->getAwSarpSubscriptionType()) {
             if ($Period->getId()) {
                 $_result[0]->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd'));
                 $_result[0]->addCustomOption('aw_sarp_subscription_type', $Period->getId());
             }
         }
         return $_result;
     }
     return $this->getSpecifyOptionMessage();
 }
Example #3
0
 /**
  * test looseBehaviour
  */
 public function testLoose()
 {
     $date = new Zend_Date(0, 'de_DE');
     try {
         $date->set(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->set(10, 'de_DE');
     $this->assertEquals(10, $date->getTimestamp());
     try {
         $date->add(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->add(10, 'de_DE');
     $this->assertEquals(20, $date->getTimestamp());
     try {
         $date->sub(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->sub(10, 'de_DE');
     $this->assertEquals(10, $date->getTimestamp());
     try {
         $date->compare(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->equals(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->isEarlier(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->isLater(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
 }
Example #4
0
 /**
  * Deletes all old log records
  *
  * @return AW_Core_Helper_Logger
  */
 public function exorcise()
 {
     $Date = new Zend_Date();
     Zend_Date::setOptions(array('extend_month' => true));
     $Date->addDayOfYear(0 - (int) Mage::getStoreConfig('awall/awcore/logger_store_days'));
     foreach (Mage::getModel('awcore/logger')->getCollection()->addOlderThanFilter($Date) as $entry) {
         $entry->delete();
     }
     return $this;
 }
 /**
  * Generates events for purchasing to subscription
  * @return AW_Sarp_Model_Subscription
  */
 protected function _generateSubscriptionEvents()
 {
     // Delete all sequencies
     if ($this->_origData['date_start'] != $this->_data['date_start'] || $this->_origData['period_type'] != $this->_data['period_type'] || !$this->getIsNew() && $this->getIsReactivated()) {
         Mage::getResourceModel('sarp/sequence')->deleteBySubscriptionId($this->getId());
         $Date = new Zend_Date(strtotime($this->getDateStart()), Zend_Date::TIMESTAMP);
         Zend_Date::setOptions(array('extend_month' => true));
         // Fix Zend_Date::addMonth unexpected result
         switch ($this->getPeriod()->getPeriodType()) {
             case 'day':
                 $method = 'addDayOfYear';
                 break;
             case 'month':
                 $method = 'addMonth';
                 break;
             case 'week':
                 $method = 'addWeek';
                 break;
             case 'year':
                 $method = 'addYear';
                 break;
             default:
                 throw new Mage_Core_Exception("Unknown subscription period type for #" . $this->getPeriod()->getId());
         }
         switch ($this->getPeriod()->getExpireType()) {
             case 'day':
                 $method_expire = 'addDayOfYear';
                 break;
             case 'month':
                 $method_expire = 'addMonth';
                 break;
             case 'week':
                 $method_expire = 'addWeek';
                 break;
             case 'year':
                 $method_expire = 'addYear';
                 break;
             default:
                 throw new Mage_Core_Exception("Unknown subscription expire period type for #" . $this->getPeriod()->getId());
         }
         $ExpireDate = clone $Date;
         $expireMultiplier = $this->getPeriod()->getExpireValue();
         if (!$expireMultiplier) {
             // 0 means infinite expiration date
             $expireMultiplier = 3;
             // 0 means expire_method = method
             $method_expire = $method;
             $_Date = $this->getLastPaidDate();
             if (is_object($_Date)) {
                 $ExpireDate = clone $_Date;
             }
         }
         $ExpireDate = call_user_func(array($ExpireDate, $method_expire), $expireMultiplier);
         // Substract delivery offset. This is
         $Date->addDayOfYear(0 - $this->getPeriod()->getPaymentOffset());
         $ExpireDate->addDayOfYear(0 - $this->getPeriod()->getPaymentOffset());
         try {
             $this->getPeriod()->validate();
             while ($Date->compare($ExpireDate) == -1) {
                 $Date = call_user_func(array($Date, $method), $this->getPeriod()->getPeriodValue());
                 Mage::getModel('sarp/sequence')->setSubscriptionId($this->getId())->setDate($Date->toString(self::DB_DATE_FORMAT))->save();
             }
         } catch (AW_Sarp_Exception $e) {
             $this->log('Unable create sequences to subscription #' . $this->getId(), AW_Core_Model_Logger::LOG_SEVERITY_WARNING, 'Unable create sequences to subscription. Message: "' . $e->getMessage() . '"');
         }
     }
     return $this;
 }
 /**
  * Prepares product for cart according to buyRequest.
  *
  * @param Varien_Object $buyRequest
  * @param object        $product [optional]
  * @return
  */
 public function prepareForCart(Varien_Object $buyRequest, $product = null, $old = false)
 {
     if (!$product->getAwSarpEnabled()) {
         if (!$old) {
             return parent::prepareForCart($buyRequest, $product);
         }
         return;
     }
     Mage::getModel('sarp/product_type_default')->checkPeriod($product, $buyRequest);
     /*
      * For creating order from admin
      * If product is added to cart from admin, we doesn't add sart custom options to it.
      */
     $Period = Mage::getModel('sarp/period');
     if ($product->getAwSarpPeriod()) {
         if (count(explode(",", $product->getAwSarpPeriod())) === 1) {
             $date = Mage::getModel('sarp/period')->load($product->getAwSarpPeriod())->getNearestAvailableDay();
             $product->setAwSarpSubscriptionType($product->getAwSarpPeriod());
             $product->setAwSarpSubscriptionStart($date->toString(), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
         }
     }
     /* We should add custom options that doesnt exist */
     if ($buyRequest->getAwSarpSubscriptionType()) {
         if ($Period->load($buyRequest->getAwSarpSubscriptionType())->getId()) {
             $product->addCustomOption('aw_sarp_subscription_type', $Period->getId());
         }
     } else {
         if ($product->getAwSarpSubscriptionType()) {
             $buyRequest->setAwSarpSubscriptionType($product->getAwSarpSubscriptionType());
             $product->addCustomOption('aw_sarp_subscription_type', $product->getAwSarpSubscriptionType());
             $Period->setId($product->getAwSarpSubscriptionStart());
         }
     }
     if ($this->requiresSubscriptionOptions($product) && !$Period->getId()) {
         $date = Mage::app()->getLocale()->date();
     }
     $options = $buyRequest->getOptions();
     if (isset($options['aw_sarp_subscription_start']) && is_array($options['aw_sarp_subscription_start']) && !empty($options['aw_sarp_subscription_start']['day']) && !empty($options['aw_sarp_subscription_start']['month']) && !empty($options['aw_sarp_subscription_start']['year'])) {
         $subscriptionStart = $options['aw_sarp_subscription_start'];
         $date = new Zend_Date();
         $date->setMinute(0)->setHour(0)->setSecond(0)->setDay($subscriptionStart['day'])->setMonth($subscriptionStart['month'])->setYear($subscriptionStart['year']);
         $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
     }
     if (!is_null($buyRequest->getAwSarpSubscriptionStart()) && $Period->getId()) {
         $start = $buyRequest->getAwSarpSubscriptionStart();
         if (!empty($start)) {
             $date = new Zend_Date($start, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
         } else {
             $date = $Period->getNearestAvailableDay();
         }
         // Check date
         // Never check if start date
         //$performDateCompare = !!Mage::getSingleton('customer/session')->getCustomer()->getId();
         $performDateCompare = !AW_Sarp_Model_Cron::$isCronSession;
         $today = new Zend_Date();
         if (!$this->isVirtual($product)) {
             $today->addDayOfYear($Period->getPaymentOffset());
         }
         if ($performDateCompare && ($date->compare($today, Zend_Date::DATE_SHORT) < 0 || !$Period->isAllowedDate($date, $product))) {
             $date = $Period->getNearestAvailableDay();
         }
     } else {
         $date = Mage::app()->getLocale()->date();
     }
     $product->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd'));
     if (!$old) {
         return parent::prepareForCart($buyRequest, $product);
     }
 }
Example #7
0
 /**
  * Returns nearest available date starting from today
  * @return Zend_Date
  */
 public function getNearestAvailableDay()
 {
     $Date = new Zend_Date();
     Zend_Date::setOptions(array('extend_month' => true));
     $Date->addDayOfYear((int) $this->getPaymentOffset());
     $exclDays = $this->getExcludedWeekdays();
     Zend_Date::setOptions(array('extend_month' => true));
     // Fix Zend_Date::addMonth unexpected result
     if (count($exclDays) == 7) {
         return $Date->addYear(99);
     }
     while (!$this->isAllowedDate($Date)) {
         $Date = $Date->addDayOfYear(1);
     }
     return $Date;
 }
 public function prepareForCartAdvanced(Varien_Object $buyRequest, $product = null, $processMode = null)
 {
     Mage::getModel('sarp/product_type_default')->checkPeriod($product, $buyRequest);
     $Period = Mage::getModel('sarp/period');
     /* We should add custom options that doesnt exist */
     if ($buyRequest->getAwSarpSubscriptionType()) {
         if ($Period->load($buyRequest->getAwSarpSubscriptionType())->getId()) {
             $product->addCustomOption('aw_sarp_subscription_type', $Period->getId());
         }
     }
     if ($this->requiresSubscriptionOptions($product) && !$Period->getId()) {
         throw new Mage_Core_Exception(Mage::helper('sarp')->__("Selected product requires subscription options"));
     }
     if ($buyRequest->getAwSarpSubscriptionStart() && $Period->getId()) {
         $date = new Zend_Date($buyRequest->getAwSarpSubscriptionStart(), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
         // Check date
         // Never check if start date
         //$performDateCompare = !!Mage::getSingleton('customer/session')->getCustomer()->getId();
         $performDateCompare = !AW_Sarp_Model_Cron::$isCronSession;
         $today = new Zend_Date();
         if (!$this->isVirtual($product)) {
             $today->addDayOfYear($Period->getPaymentOffset());
         }
         if ($performDateCompare && ($date->compare($today, Zend_Date::DATE_SHORT) < 0 || !$Period->isAllowedDate($date, $product))) {
             throw new Mage_Core_Exception(Mage::helper('sarp')->__("Selected date is not valid for specified period"));
         }
     } else {
         $date = Mage::app()->getLocale()->date();
     }
     $product->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd'));
     $result = Mage_Catalog_Model_Product_Type_Virtual::prepareForCartAdvanced($buyRequest, $product);
     if (is_string($result)) {
         return $result;
     }
     $preparedLinks = array();
     if ($this->getProduct($product)->getLinksPurchasedSeparately()) {
         if ($links = $buyRequest->getLinks()) {
             foreach ($this->getLinks($product) as $link) {
                 if (in_array($link->getId(), $links)) {
                     $preparedLinks[] = $link->getId();
                 }
             }
         }
     } else {
         foreach ($this->getLinks($product) as $link) {
             $preparedLinks[] = $link->getId();
         }
     }
     if ($preparedLinks) {
         $this->getProduct($product)->addCustomOption('downloadable_link_ids', implode(',', $preparedLinks));
         return $result;
     }
     return $result;
 }
 public function prepareForCartAdvanced(Varien_Object $buyRequest, $product = null, $processMode = null)
 {
     Mage::getModel('sarp/product_type_default')->checkPeriod($product, $buyRequest);
     $Period = Mage::getModel('sarp/period');
     /* We should add custom options that doesnt exist */
     if ($buyRequest->getAwSarpSubscriptionType()) {
         if ($Period->load($buyRequest->getAwSarpSubscriptionType())->getId()) {
             $product->addCustomOption('aw_sarp_subscription_type', $Period->getId());
         }
     }
     $options = $buyRequest->getOptions();
     if (isset($options['aw_sarp_subscription_start']) && is_array($options['aw_sarp_subscription_start'])) {
         $subscriptionStart = $options['aw_sarp_subscription_start'];
         $date = new Zend_Date();
         $date->setMinute(0)->setHour(0)->setSecond(0)->setDay($subscriptionStart['day'])->setMonth($subscriptionStart['month'])->setYear($subscriptionStart['year']);
         $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
     }
     if ($buyRequest->getAwSarpSubscriptionStart() && $Period->getId()) {
         $date = new Zend_Date($buyRequest->getAwSarpSubscriptionStart(), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
         // Check date
         // Never check if start date
         //$performDateCompare = !!Mage::getSingleton('customer/session')->getCustomer()->getId();
         $performDateCompare = !AW_Sarp_Model_Cron::$isCronSession;
         $today = new Zend_Date();
         if (!$this->isVirtual($product)) {
             $today->addDayOfYear($Period->getPaymentOffset());
         }
         if ($performDateCompare && ($date->compare($today, Zend_Date::DATE_SHORT) < 0 || !$Period->isAllowedDate($date, $product))) {
             throw new Mage_Core_Exception(Mage::helper('sarp')->__("Selected date is not valid for specified period"));
         }
     } else {
         $date = Mage::app()->getLocale()->date();
     }
     $product->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd'));
     if ($attributes = $buyRequest->getSuperAttribute()) {
         $result = Mage_Catalog_Model_Product_Type_Abstract::prepareForCartAdvanced($buyRequest, $product);
         if (is_array($result)) {
             $product = $this->getProduct($product);
             /**
              * $attributes = array($attributeId=>$attributeValue)
              */
             if ($subProduct = $this->getProductByAttributes($attributes, $product)) {
                 $product->addCustomOption('attributes', serialize($attributes));
                 $product->addCustomOption('product_qty_' . $subProduct->getId(), 1, $subProduct);
                 $product->addCustomOption('simple_product', $subProduct->getId(), $subProduct);
                 $_result = $subProduct->getTypeInstance(true)->prepareForCartAdvanced($buyRequest, $subProduct);
                 if (is_string($_result) && !is_array($_result)) {
                     return $_result;
                 }
                 if (!isset($_result[0])) {
                     return Mage::helper('checkout')->__('Can not add item to shopping cart');
                 }
                 /**
                  * Adding parent product custom options to child product
                  * to be sure that it will be unique as its parent
                  */
                 if ($optionIds = $product->getCustomOption('option_ids')) {
                     $optionIds = explode(',', $optionIds->getValue());
                     foreach ($optionIds as $optionId) {
                         if ($option = $product->getCustomOption('option_' . $optionId)) {
                             $_result[0]->addCustomOption('option_' . $optionId, $option->getValue());
                         }
                     }
                 }
                 if ($buyRequest->getAwSarpSubscriptionType()) {
                     if ($Period->getId()) {
                         $_result[0]->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd'));
                         $_result[0]->addCustomOption('aw_sarp_subscription_type', $Period->getId());
                     }
                 }
                 $_result[0]->setParentProductId($product->getId())->addCustomOption('parent_product_id', $product->getId())->setCartQty(1);
                 $result[] = $_result[0];
                 return $result;
             }
         }
     }
     return $this->getSpecifyOptionMessage();
 }