Example #1
0
 /**
  * Initialize gift card for add to cart process
  *
  * @param Varien_Object $buyRequest
  * @param Mage_Catalog_Model_Product $product
  * @return array|string
  */
 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
 {
     $product = $this->getProduct($product);
     $data = $buyRequest->getData();
     $cardType = $product->getAttributeText('wts_gc_type');
     //change delivery date to mysql format
     if (!empty($data['mail_delivery_date'])) {
         $tempDate = explode('/', $data['mail_delivery_date']);
         $mailDeliveryDate = $tempDate[2] . '-' . $tempDate[0] . '-' . $tempDate[1];
     } else {
         $mailDeliveryDate = null;
     }
     /*
      * Validate card amount
      * TODO: Need options validation
      */
     if (!$product->getPrice() || $product->getPrice() == 0) {
         // true only if min value is set (more than 0) and price less than min
         $min = Mage::getStoreConfig('giftcards/default/min_card_value') > 0 && $data['card_amount'] < Mage::getStoreConfig('giftcards/default/min_card_value');
         // true only if max value is set (more than 0) and price more than max
         $max = Mage::getStoreConfig('giftcards/default/max_card_value') > 0 && $data['card_amount'] > Mage::getStoreConfig('giftcards/default/max_card_value');
         // if one of conditions above is true than return error
         if ($min || $max) {
             return $this->getSpecifyPriceMessage();
         }
     }
     /*
      * Validate card type
      * TODO: Need options validation
      */
     /* if (!isset($data['card_type']) || !in_array($data['card_type'], array('email', 'print', 'offline'))) {
            return $this->getSpecifyOptionsMessage();
        }*/
     /*
      * Add gift card params as product custom options to product quote
      * TODO: Need options validation
      */
     $product->addCustomOption('card_type', $cardType);
     $product->addCustomOption('card_amount', isset($data['card_amount']) ? $data['card_amount'] : $product->getPrice());
     $product->addCustomOption('card_currency', Mage::app()->getStore()->getCurrentCurrencyCode());
     $product->addCustomOption('mail_to', isset($data['mail_to']) ? $data['mail_to'] : '');
     $product->addCustomOption('mail_to_email', isset($data['mail_to_email']) ? $data['mail_to_email'] : '');
     $product->addCustomOption('mail_from', isset($data['mail_from']) ? $data['mail_from'] : '');
     $product->addCustomOption('mail_message', isset($data['mail_message']) ? $data['mail_message'] : '');
     $product->addCustomOption('offline_country', isset($data['offline_country']) ? $data['offline_country'] : '');
     $product->addCustomOption('offline_state', isset($data['offline_state']) ? $data['offline_state'] : '');
     $product->addCustomOption('offline_city', isset($data['offline_city']) ? $data['offline_city'] : '');
     $product->addCustomOption('offline_street', isset($data['offline_street']) ? $data['offline_street'] : '');
     $product->addCustomOption('offline_zip', isset($data['offline_zip']) ? $data['offline_zip'] : '');
     $product->addCustomOption('offline_phone', isset($data['offline_phone']) ? $data['offline_phone'] : '');
     $product->addCustomOption('mail_delivery_date', $mailDeliveryDate);
     //delivery date of email
     return parent::_prepareProduct($buyRequest, $product, $processMode);
 }
Example #2
0
 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
 {
     if (version_compare(Mage::getVersion(), '1.5.0', '<')) {
         return parent::_prepareProduct($buyRequest, $product, $processMode);
     }
     if (is_null($product)) {
         $product = $this->getProduct();
     }
     $result = parent::_prepareProduct($buyRequest, $product, $processMode);
     if (is_string($result)) {
         return $result;
     }
     reset($result);
     $product = current($result);
     $result = $this->_prepareWebPOSProduct($buyRequest, $product);
     return $result;
 }
Example #3
0
 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
 {
     $product = $this->getProduct($product);
     $servicePrice = (double) $buyRequest->getServicePrice();
     $isStrictProcessMode = $this->_isStrictProcessMode($processMode);
     if ($buyRequest->getQty() > 1) {
         return Mage::helper('catalog')->__('The maximum qty of service product allowed in cart is 1.');
     }
     if (!$isStrictProcessMode || $servicePrice > 0) {
         $maxPrice = Mage::helper('service_product')->getMaxPrice();
         if ($maxPrice && $servicePrice > $maxPrice) {
             return Mage::helper('catalog')->__('Service price must not be greater than %d.', $maxPrice);
         }
         $products = parent::_prepareProduct($buyRequest, $product, $processMode);
         if (!isset($products[0])) {
             return Mage::helper('checkout')->__('Cannot process the item.');
         }
         return $products;
     }
     return Mage::helper('catalog')->__('Please specify the product price.');
 }
Example #4
0
 /**
  * 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)
 {
     $attributes = $buyRequest->getSuperAttribute();
     if ($attributes || !$this->_isStrictProcessMode($processMode)) {
         if (!$this->_isStrictProcessMode($processMode)) {
             if (is_array($attributes)) {
                 foreach ($attributes as $key => $val) {
                     if (empty($val)) {
                         unset($attributes[$key]);
                     }
                 }
             } else {
                 $attributes = array();
             }
         }
         $result = parent::_prepareProduct($buyRequest, $product, $processMode);
         if (is_array($result)) {
             $product = $this->getProduct($product);
             /**
              * $attributes = array($attributeId=>$attributeValue)
              */
             $subProduct = true;
             if ($this->_isStrictProcessMode($processMode)) {
                 foreach ($this->getConfigurableAttributes($product) as $attributeItem) {
                     $attrId = $attributeItem->getData('attribute_id');
                     if (!isset($attributes[$attrId]) || empty($attributes[$attrId])) {
                         $subProduct = null;
                         break;
                     }
                 }
             }
             if ($subProduct) {
                 $subProduct = $this->getProductByAttributes($attributes, $product);
             }
             if ($subProduct) {
                 $product->addCustomOption('attributes', serialize($attributes));
                 $product->addCustomOption('product_qty_' . $subProduct->getId(), 1, $subProduct);
                 $product->addCustomOption('simple_product', $subProduct->getId(), $subProduct);
                 $_result = $subProduct->getTypeInstance(true)->_prepareProduct($buyRequest, $subProduct, $processMode);
                 if (is_string($_result) && !is_array($_result)) {
                     return $_result;
                 }
                 if (!isset($_result[0])) {
                     return Mage::helper('checkout')->__('Cannot add the 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());
                         }
                     }
                 }
                 $_result[0]->setParentProductId($product->getId())->addCustomOption('parent_product_id', $product->getId());
                 if ($this->_isStrictProcessMode($processMode)) {
                     $_result[0]->setCartQty(1);
                 }
                 $result[] = $_result[0];
                 return $result;
             } else {
                 if (!$this->_isStrictProcessMode($processMode)) {
                     return $result;
                 }
             }
         }
     }
     return $this->getSpecifyOptionMessage();
 }
Example #5
0
 /**
  * Prepare product and its configuration to be added to some products list.
  * Perform standard preparation process and then prepare of bundle selections 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)
 {
     $result = parent::_prepareProduct($buyRequest, $product, $processMode);
     if (is_string($result)) {
         return $result;
     }
     $selections = array();
     $product = $this->getProduct($product);
     $isStrictProcessMode = $this->_isStrictProcessMode($processMode);
     $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
     $_appendAllSelections = (bool) $product->getSkipCheckRequiredOption() || $skipSaleableCheck;
     $options = $buyRequest->getBundleOption();
     if (is_array($options)) {
         $options = array_filter($options, 'intval');
         $qtys = $buyRequest->getBundleOptionQty();
         foreach ($options as $_optionId => $_selections) {
             if (empty($_selections)) {
                 unset($options[$_optionId]);
             }
         }
         $optionIds = array_keys($options);
         if (empty($optionIds) && $isStrictProcessMode) {
             return Mage::helper('bundle')->__('Please select options for product.');
         }
         $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
         $optionsCollection = $this->getOptionsCollection($product);
         if (!$this->getProduct($product)->getSkipCheckRequiredOption() && $isStrictProcessMode) {
             foreach ($optionsCollection->getItems() as $option) {
                 if ($option->getRequired() && !isset($options[$option->getId()])) {
                     return Mage::helper('bundle')->__('Required options are not selected.');
                 }
             }
         }
         $selectionIds = array();
         foreach ($options as $optionId => $selectionId) {
             if (!is_array($selectionId)) {
                 if ($selectionId != '') {
                     $selectionIds[] = (int) $selectionId;
                 }
             } else {
                 foreach ($selectionId as $id) {
                     if ($id != '') {
                         $selectionIds[] = (int) $id;
                     }
                 }
             }
         }
         // If product has not been configured yet then $selections array should be empty
         if (!empty($selectionIds)) {
             $selections = $this->getSelectionsByIds($selectionIds, $product);
             // Check if added selections are still on sale
             foreach ($selections->getItems() as $key => $selection) {
                 if (!$selection->isSalable() && !$skipSaleableCheck) {
                     $_option = $optionsCollection->getItemById($selection->getOptionId());
                     if (is_array($options[$_option->getId()]) && count($options[$_option->getId()]) > 1) {
                         $moreSelections = true;
                     } else {
                         $moreSelections = false;
                     }
                     if ($_option->getRequired() && (!$_option->isMultiSelection() || $_option->isMultiSelection() && !$moreSelections)) {
                         return Mage::helper('bundle')->__('Selected required options are not available.');
                     }
                 }
             }
             $optionsCollection->appendSelections($selections, false, $_appendAllSelections);
             $selections = $selections->getItems();
         } else {
             $selections = array();
         }
     } else {
         $product->setOptionsValidationFail(true);
         $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
         $optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
         $optionIds = $product->getTypeInstance(true)->getOptionsIds($product);
         $selectionIds = array();
         $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection($optionIds, $product);
         $options = $optionCollection->appendSelections($selectionCollection, false, $_appendAllSelections);
         foreach ($options as $option) {
             if ($option->getRequired() && count($option->getSelections()) == 1) {
                 $selections = array_merge($selections, $option->getSelections());
             } else {
                 $selections = array();
                 break;
             }
         }
     }
     if (count($selections) > 0 || !$isStrictProcessMode) {
         $uniqueKey = array($product->getId());
         $selectionIds = array();
         // Shuffle selection array by option position
         usort($selections, array($this, 'shakeSelections'));
         foreach ($selections as $selection) {
             if ($selection->getSelectionCanChangeQty() && isset($qtys[$selection->getOptionId()])) {
                 $qty = (double) $qtys[$selection->getOptionId()] > 0 ? $qtys[$selection->getOptionId()] : 1;
             } else {
                 $qty = (double) $selection->getSelectionQty() ? $selection->getSelectionQty() : 1;
             }
             $qty = (double) $qty;
             $product->addCustomOption('selection_qty_' . $selection->getSelectionId(), $qty, $selection);
             $selection->addCustomOption('selection_id', $selection->getSelectionId());
             $beforeQty = 0;
             $customOption = $product->getCustomOption('product_qty_' . $selection->getId());
             if ($customOption) {
                 $beforeQty = (double) $customOption->getValue();
             }
             $product->addCustomOption('product_qty_' . $selection->getId(), $qty + $beforeQty, $selection);
             /*
              * Create extra attributes that will be converted to product options in order item
              * for selection (not for all bundle)
              */
             $price = $product->getPriceModel()->getSelectionFinalTotalPrice($product, $selection, 0, $qty);
             $attributes = array('price' => Mage::app()->getStore()->convertPrice($price), 'qty' => $qty, 'option_label' => $selection->getOption()->getTitle(), 'option_id' => $selection->getOption()->getId());
             $_result = $selection->getTypeInstance(true)->prepareForCart($buyRequest, $selection);
             if (is_string($_result) && !is_array($_result)) {
                 return $_result;
             }
             if (!isset($_result[0])) {
                 return Mage::helper('checkout')->__('Cannot add item to the shopping cart.');
             }
             $result[] = $_result[0]->setParentProductId($product->getId())->addCustomOption('bundle_option_ids', serialize(array_map('intval', $optionIds)))->addCustomOption('bundle_selection_attributes', serialize($attributes));
             if ($isStrictProcessMode) {
                 $_result[0]->setCartQty($qty);
             }
             $selectionIds[] = $_result[0]->getSelectionId();
             $uniqueKey[] = $_result[0]->getSelectionId();
             $uniqueKey[] = $qty;
         }
         // "unique" key for bundle selection and add it to selections and bundle for selections
         $uniqueKey = implode('_', $uniqueKey);
         foreach ($result as $item) {
             $item->addCustomOption('bundle_identity', $uniqueKey);
         }
         $product->addCustomOption('bundle_option_ids', serialize(array_map('intval', $optionIds)));
         $product->addCustomOption('bundle_selection_ids', serialize($selectionIds));
         return $result;
     }
     return $this->getSpecifyOptionMessage();
 }
Example #6
0
 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
 {
     $result = array();
     if (method_exists(get_parent_class($this), 'prepareForCartAdvanced')) {
         $result = parent::_prepareProduct($buyRequest, $product, $processMode);
         if (is_string($result)) {
             return $result;
         }
     }
     try {
         $amount = $this->_validateAndGetAmount($buyRequest, $product, $processMode);
     } catch (Mage_Core_Exception $e) {
         return $e->getMessage();
     } catch (Exception $e) {
         Mage::logException($e);
         return Mage::helper('aw_giftcard')->__('An error has occurred while adding product to cart.');
     }
     $product->addCustomOption('aw_gc_amounts', $amount, $product);
     $product->addCustomOption('aw_gc_sender_name', $buyRequest->getAwGcSenderName(), $product);
     $product->addCustomOption('aw_gc_recipient_name', $buyRequest->getAwGcRecipientName(), $product);
     if (!$this->isTypePhysical($product)) {
         $product->addCustomOption('aw_gc_sender_email', $buyRequest->getAwGcSenderEmail(), $product);
         $product->addCustomOption('aw_gc_recipient_email', $buyRequest->getAwGcRecipientEmail(), $product);
     }
     $messageAllowed = (bool) $product->getAwGcAllowMessage();
     if ($product->getAwGcConfigAllowMessage()) {
         $messageAllowed = (bool) Mage::helper('aw_giftcard/config')->isAllowGiftMessage();
     }
     if ($messageAllowed) {
         $product->addCustomOption('aw_gc_message', trim($buyRequest->getAwGcMessage()), $product);
     }
     return $result;
 }
 /**
  * Prepare product and its configuration to be added to some products list.
  * Use standard preparation process and also add specific giftcard 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)
 {
     $result = parent::_prepareProduct($buyRequest, $product, $processMode);
     if (is_string($result)) {
         return $result;
     }
     try {
         $amount = $this->_validate($buyRequest, $product, $processMode);
     } catch (Mage_Core_Exception $e) {
         return $e->getMessage();
     } catch (Exception $e) {
         Mage::logException($e);
         return Mage::helper('enterprise_giftcard')->__('An error has occurred while preparing Gift Card.');
     }
     $product->addCustomOption('giftcard_amount', $amount, $product);
     $product->addCustomOption('giftcard_sender_name', $buyRequest->getGiftcardSenderName(), $product);
     $product->addCustomOption('giftcard_recipient_name', $buyRequest->getGiftcardRecipientName(), $product);
     if (!$this->isTypePhysical($product)) {
         $product->addCustomOption('giftcard_sender_email', $buyRequest->getGiftcardSenderEmail(), $product);
         $product->addCustomOption('giftcard_recipient_email', $buyRequest->getGiftcardRecipientEmail(), $product);
     }
     $messageAllowed = false;
     if ($product->getUseConfigAllowMessage()) {
         $messageAllowed = Mage::getStoreConfigFlag(Enterprise_GiftCard_Model_Giftcard::XML_PATH_ALLOW_MESSAGE);
     } else {
         $messageAllowed = (int) $product->getAllowMessage();
     }
     if ($messageAllowed) {
         $product->addCustomOption('giftcard_message', $buyRequest->getGiftcardMessage(), $product);
     }
     return $result;
 }
Example #8
0
 /**
  * Prepare product and its configuration to be added to some products list.
  * Perform standard preparation process and add logic specific to kitted product type.
  *
  * @param Varien_Object              $buyRequest
  * @param Mage_Catalog_Model_Product $product
  * @param string                     $processMode
  *
  * @return Mage_Catalog_Model_Product[]|string
  */
 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
 {
     /** @var Mage_Catalog_Model_Product[] $products */
     $products = Mage_Catalog_Model_Product_Type_Abstract::_prepareProduct($buyRequest, $product, $processMode);
     if (!is_array($products)) {
         return $products;
     }
     if (empty($products)) {
         return Mage::helper('OpenMage_KittedProduct/Data')->__('Cannot process the item.');
     }
     /** @var Mage_Catalog_Model_Product $parentProduct */
     $parentProduct = $products[0];
     /** @var Mage_Catalog_Model_Product[] $associatedProducts */
     $associatedProducts = $this->getAssociatedProducts($product);
     if ($associatedProducts && $this->_isStrictProcessMode($processMode)) {
         foreach ($associatedProducts as $subProduct) {
             $buyRequest->setQty($parentProduct->getQty() * $subProduct->getQty());
             $result = $subProduct->getTypeInstance(true)->processConfiguration($buyRequest, $subProduct, $processMode);
             if (!is_array($result)) {
                 return $result;
             }
             if (empty($result)) {
                 return Mage::helper('OpenMage_KittedProduct/Data')->__('Cannot process the item.');
             }
             /** @var Mage_Catalog_Model_Product $subProduct */
             $subProduct = reset($result);
             $subProduct->setParentProductId($parentProduct->getId());
             $subProduct->setCartQty($subProduct->getQty());
             $parentProduct->addCustomOption('product_qty_' . $subProduct->getId(), $subProduct->getQty(), $subProduct);
             $products[] = $subProduct;
         }
     }
     return $products;
 }
Example #9
0
 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
 {
     $result = parent::_prepareProduct($buyRequest, $product, $processMode);
     return $this->addGiftCardOptions($buyRequest, $product, $result);
 }