Example #1
0
 public function prepareForCart(Varien_Object $buyRequest, $product = null)
 {
     $product = $this->getProduct($product);
     parent::prepareForCart($buyRequest, $product);
     if ($buyRequest->getcpid()) {
         $product->addCustomOption('cpid', $buyRequest->getcpid());
     }
     return array($product);
 }
 /**
  * Prepares product for cart according to buyRequest.
  *
  * @param Varien_Object $buyRequest
  * @param object        $product [optional]
  * @return
  */
 public function prepareForCart(Varien_Object $buyRequest, $product = 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::prepareForCart($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;
 }
 /**
  * Prepare Product object before adding to Shopping Cart
  *
  * @param Varien_Object $buyRequest
  * @param Mage_Catalog_Model_Product $product
  * @return array|string
  */
 public function prepareForCart(Varien_Object $buyRequest, $product = null)
 {
     $result = parent::prepareForCart($buyRequest, $product);
     if (is_string($result)) {
         return $result;
     }
     // if adding product from admin area we add all links to product
     if ($this->getProduct($product)->getSkipCheckRequiredOption()) {
         $this->getProduct($product)->setLinksPurchasedSeparately(false);
     }
     $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;
     }
     if ($this->getLinkSelectionRequired($product)) {
         return Mage::helper('downloadable')->__('Please specify product link(s).');
     }
     return $result;
 }