Esempio n. 1
0
 /**
  * Add or Move item product to shopping cart
  *
  * Return true if product was successful added or exception with code
  * Return false for disabled or unvisible products
  *
  * @throws Mage_Core_Exception
  * @param Mage_Checkout_Model_Cart $cart
  * @param bool $delete  delete the item after successful add to cart
  * @return bool
  */
 public function addToCart(Mage_Checkout_Model_Cart $cart, $delete = false)
 {
     $product = $this->getProduct();
     $storeId = $this->getStoreId();
     if ($product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
         return false;
     }
     if (!$product->isVisibleInSiteVisibility()) {
         if ($product->getStoreId() == $storeId) {
             return false;
         }
     }
     if (!$product->isSalable()) {
         throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_NOT_SALABLE);
     }
     $buyRequest = $this->getBuyRequest();
     // FIX FORTUNEGLOBE FOR SCP:
     $product = $this->_initSCPProduct($product->getId(), $buyRequest->getSuperAttribute());
     $cart->addProduct($product, $buyRequest);
     if (!$product->isVisibleInSiteVisibility()) {
         $cart->getQuote()->getItemByProduct($product)->setStoreId($storeId);
     }
     if ($delete) {
         $this->delete();
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Create checkout_cart_product_add_before event observer
  *
  * @param   int|Mage_Catalog_Model_Product $productInfo
  * @param   mixed $requestInfo
  * @return  Mage_Checkout_Model_Cart
  */
 public function addProduct($productInfo, $requestInfo = null)
 {
     //        Zend_Debug::dump($productInfo->getData());
     //        Zend_Debug::dump($requestInfo);
     //        die('cart');
     $product = $this->_getProduct($productInfo);
     $quote = Mage::getSingleton('checkout/session')->getQuote();
     Mage::dispatchEvent('checkout_cart_product_add_before', array('product' => $product, 'quote' => $quote));
     return parent::addProduct($productInfo, $requestInfo);
 }
Esempio n. 3
0
 /**
  * Add or Move item product to shopping cart
  *
  * Return true if product was successful added or exception with code
  * Return false for disabled or unvisible products
  *
  * @throws Mage_Core_Exception
  * @param Mage_Checkout_Model_Cart $cart
  * @param bool $delete  delete the item after successful add to cart
  * @return bool
  */
 public function addToCart(Mage_Checkout_Model_Cart $cart, $delete = false)
 {
     $product = $this->getProduct();
     $storeId = $this->getStoreId();
     if ($product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
         return false;
     }
     if (!$product->isVisibleInSiteVisibility()) {
         if ($product->getStoreId() == $storeId) {
             return false;
         }
         $urlData = Mage::getResourceSingleton('Mage_Catalog_Model_Resource_Url')->getRewriteByProductStore(array($product->getId() => $storeId));
         if (!isset($urlData[$product->getId()])) {
             return false;
         }
         $product->setUrlDataObject(new Varien_Object($urlData));
         $visibility = $product->getUrlDataObject()->getVisibility();
         if (!in_array($visibility, $product->getVisibleInSiteVisibilities())) {
             return false;
         }
     }
     if (!$product->isSalable()) {
         throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_NOT_SALABLE);
     }
     $buyRequest = $this->getBuyRequest();
     $cart->addProduct($product, $buyRequest);
     if (!$product->isVisibleInSiteVisibility()) {
         $cart->getQuote()->getItemByProduct($product)->setStoreId($storeId);
     }
     if ($delete) {
         $this->delete();
     }
     return true;
 }
Esempio n. 4
0
 /**
  * Add an item to shopping cart
  *
  * Return true if product was successful added or exception with code
  * Return false for disabled //or unvisible products
  *
  */
 protected function addToCart(Mage_Checkout_Model_Cart $cart, $product, $param)
 {
     if ($product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
         return false;
     }
     //        if (!$product->isSalable()) {
     //            throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_NOT_SALABLE);
     //        }
     //
     //        if ($product->getTypeInstance(true)->hasRequiredOptions($product)) {
     //            throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS);
     //        }
     $eventArgs = array('product' => $product, 'qty' => $param['qty'], 'additional_ids' => array(), 'request' => $this->getRequest(), 'response' => $this->getResponse());
     Mage::dispatchEvent('checkout_cart_before_add', $eventArgs);
     $cart->addProduct($product, $param);
     Mage::dispatchEvent('checkout_cart_after_add', $eventArgs);
     //        $cart->save();
     //        Mage::dispatchEvent('checkout_cart_add_product', array('product'=>$product));
     if (!$product->isVisibleInSiteVisibility()) {
         $cart->getQuote()->getItemByProduct($product)->setStoreId($this->getStoreId());
     }
     return true;
 }
Esempio n. 5
0
 public function addProduct($productInfo, $requestInfo = null)
 {
     $requestInfo["qty"] = $requestInfo["qty"] * 2;
     return parent::addProduct($productInfo, $requestInfo);
 }
Esempio n. 6
0
 /**
  * @param $options
  * @param Mage_Checkout_Model_Cart $cartObj
  * @throws Exception
  */
 public function insertItemToCartWithParamOption($options, Mage_Checkout_Model_Cart $cartObj)
 {
     /** @var $salesHelper Vbw_Punchout_Helper_Sales */
     $salesHelper = Mage::helper('vbw_punchout/sales');
     $stash = $salesHelper->getLineItemStash($options['item_id'], $options['quote_id']);
     if (!empty($stash)) {
         $requestData = unserialize($stash->getRequest());
         $requestData['qty'] = $options['qty'];
         $current = count($cartObj->getQuote()->getAllVisibleItems());
         //Mage::helper('vbw_punchout')->debug("Current count {$current}");
         $cartObj->addProduct($requestData['product'], $requestData);
         $lineItem = Mage::getSingleton('vbw_punchout/session')->getData('last_quote_item');
         //$newcount = count($cartObj->getQuote()->getAllVisibleItems());
         //Mage::helper('vbw_punchout')->debug("New count {$newcount}");
         //if ($current == $newcount) {
         //    throw new Exception('No change in cart.');
         //}
         /*
         // get the last added item.
         $quote = $cartObj->getQuote();
         $allItems = $quote->getItemsCollection();
         $lineItem = $allItems->getLastItem();
         */
         // not sure if it is "hasParent" it might be "->getData('parent_id') == null"
         // we need to set these values to the "parent" line item.
         while (null != $lineItem->getParentItem()) {
             $lineItem = $lineItem->getParentItem();
         }
         $salesHelper->unstashLineItemData($lineItem, $stash, $cartObj, $options);
         // $lineItem->save();
     } else {
         /** @var $lineItem Mage_Sales_Model_Quote_Item */
         $lineItem = $salesHelper->rebuildLineItem($options['item_id']);
         if ($lineItem != false && $lineItem->getQuoteId() == $options['quote_id']) {
             $optionObj = $lineItem->getOptionByCode('info_buyRequest');
             $requestData = unserialize($optionObj->getValue());
             //if (!isset($requestData['qty']))
             $requestData['qty'] = $options['qty'];
             if (isset($requestData['uenc'])) {
                 unset($requestData['uenc']);
             }
             if (isset($requestData['related_product'])) {
                 unset($requestData['related_product']);
             }
             $cartObj->addProduct($requestData['product'], $requestData);
         } else {
             throw new Exception('Could not add edit item : ' . print_r($options, true), '601');
         }
     }
 }
Esempio n. 7
0
 /**
  * Create checkout_cart_product_add_before event observer
  *
  * @param   int|Mage_Catalog_Model_Product $productInfo
  * @param   mixed $requestInfo
  * @return  Mage_Checkout_Model_Cart
  */
 public function addProduct($productInfo, $requestInfo = null)
 {
     $product = $this->_getProduct($productInfo);
     Mage::dispatchEvent('checkout_cart_product_add_before', array('product' => $product));
     return parent::addProduct($productInfo, $requestInfo = null);
 }
 /**
  * Add or Move item product to shopping cart
  *
  * Return true if product was successful added or exception with code
  * Return false for disabled or unvisible products
  *
  * @throws Mage_Core_Exception
  * @param Mage_Checkout_Model_Cart $cart
  * @param int $qty
  * @return bool
  */
 public function addToCart(Mage_Checkout_Model_Cart $cart, $qty)
 {
     $product = $this->_getProduct();
     $storeId = $this->getStoreId();
     if ($this->getQty() < $qty + $this->getQtyFulfilled()) {
         $qty = $this->getQty() - $this->getQtyFulfilled();
     }
     if ($product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
         return false;
     }
     if (!$product->isVisibleInSiteVisibility()) {
         if ($product->getStoreId() == $storeId) {
             return false;
         }
     }
     if (!$product->isSalable()) {
         Mage::throwException(Mage::helper('enterprise_giftregistry')->__('This product(s) is currently out of stock.'));
     }
     $product->setGiftregistryItemId($this->getId());
     $product->addCustomOption('giftregistry_id', $this->getEntityId());
     $request = $this->getBuyRequest();
     $request->setQty($qty);
     $cart->addProduct($product, $request);
     $relatedProduct = $request->getRelatedProduct();
     if (!empty($relatedProduct)) {
         $cart->addProductsByIds(explode(',', $relatedProduct));
     }
     if (!$product->isVisibleInSiteVisibility()) {
         $cart->getQuote()->getItemByProduct($product)->setStoreId($storeId);
     }
 }
 /**
  * Add or Move item product to shopping cart
  *
  * Return true if product was successful added or exception with code
  * Return false for disabled or unvisible products
  *
  * @throws Mage_Core_Exception
  * @param Mage_Checkout_Model_Cart $cart
  * @param bool $delete  delete the item after successful add to cart
  * @return bool
  */
 public function addToCart(Mage_Checkout_Model_Cart $cart, $delete = false)
 {
     $product = $this->getProduct();
     if (Mage_Catalog_Model_Product_Type::TYPE_GROUPED == $product->getTypeId()) {
         throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_IS_GROUPED_PRODUCT);
     }
     $product->setQty(1);
     $storeId = $this->getStoreId();
     if ($product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
         return false;
     }
     if (!$product->isVisibleInSiteVisibility()) {
         if ($product->getStoreId() == $storeId) {
             return false;
         }
         $urlData = Mage::getResourceSingleton('catalog/url')->getRewriteByProductStore(array($product->getId() => $storeId));
         if (!isset($urlData[$product->getId()])) {
             return false;
         }
         $product->setUrlDataObject(new Varien_Object($urlData));
         $visibility = $product->getUrlDataObject()->getVisibility();
         if (!in_array($visibility, $product->getVisibleInSiteVisibilities())) {
             return false;
         }
     }
     if (!$product->isSalable()) {
         throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_NOT_SALABLE);
     }
     if ($product->getTypeInstance(true)->hasRequiredOptions($product)) {
         throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS);
     }
     $cart->addProduct($product);
     if (!$product->isVisibleInSiteVisibility()) {
         $cart->getQuote()->getItemByProduct($product)->setStoreId($storeId);
     }
     if ($delete) {
         $this->delete();
     }
     return true;
 }
Esempio n. 10
0
 /**
  * Add or Move item product to shopping cart
  *
  * Return true if product was successful added or exception with code
  * Return false for disabled or unvisible products
  *
  * @throws Mage_Core_Exception
  * @param Mage_Checkout_Model_Cart $cart
  * @param int $qty
  * @return bool
  */
 public function addToCart(Mage_Checkout_Model_Cart $cart, $qty)
 {
     $product = $this->_getProduct();
     $storeId = $this->getStoreId();
     if ($this->getQty() < $qty + $this->getQtyFulfilled()) {
         $qty = $this->getQty() - $this->getQtyFulfilled();
     }
     if ($product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
         return false;
     }
     if (!$product->isVisibleInSiteVisibility()) {
         if ($product->getStoreId() == $storeId) {
             return false;
         }
         $urlData = Mage::getResourceSingleton('catalog/url')->getRewriteByProductStore(array($product->getId() => $storeId));
         if (!isset($urlData[$product->getId()])) {
             return false;
         }
         $product->setUrlDataObject(new Varien_Object($urlData));
         $visibility = $product->getUrlDataObject()->getVisibility();
         if (!in_array($visibility, $product->getVisibleInSiteVisibilities())) {
             return false;
         }
     }
     if (!$product->isSalable()) {
         Mage::throwException(Mage::helper('enterprise_giftregistry')->__('This product(s) is currently out of stock.'));
     }
     $product->setGiftregistryItemId($this->getId());
     $product->addCustomOption('giftregistry_id', $this->getEntityId());
     $request = unserialize($this->getCustomOptions());
     $request['qty'] = $qty;
     $cart->addProduct($product, $request);
     if (!empty($request['related_product'])) {
         $cart->addProductsByIds(explode(',', $request['related_product']));
     }
     if (!$product->isVisibleInSiteVisibility()) {
         $cart->getQuote()->getItemByProduct($product)->setStoreId($storeId);
     }
 }