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; }