Example #1
0
 /**
  * Validate stock of a quoteItem
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @param float                       $priceInclTax
  * @param float                       $priceExclTax
  * @return ShopgateCartItem $result
  */
 public function validateStock(Mage_Sales_Model_Quote_Item $item, $priceInclTax, $priceExclTax)
 {
     /** @var Mage_Catalog_Model_Product $product */
     $product = $item->getProduct();
     /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */
     $stockItem = $product->getStockItem();
     $isBuyable = true;
     if ($product->isConfigurable()) {
         $parent = $product;
         $product = $product->getCustomOption('simple_product')->getProduct();
         $product->setShopgateItemNumber($parent->getShopgateItemNumber());
         $product->setShopgateOptions($parent->getShopgateOptions());
         $product->setShopgateInputs($parent->getShopgateInputs());
         $product->setShhopgateAttributes($parent->getShhopgateAttributes());
         $stockItem = $item->getProduct()->getCustomOption('simple_product')->getProduct()->getStockItem();
     }
     $errors = array();
     if (Mage::helper('shopgate/config')->getIsMagentoVersionLower1410()) {
         $checkIncrements = Mage::helper('shopgate')->checkQtyIncrements($stockItem, $item->getQty());
     } else {
         $checkIncrements = $stockItem->checkQtyIncrements($item->getQty());
     }
     if ($stockItem->getManageStock() && !$product->isSaleable() && (!$stockItem->getBackorders() || !$stockItem->getIsInStock())) {
         $isBuyable = false;
         $error = array();
         $error['type'] = ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK;
         $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK);
         $errors[] = $error;
     } else {
         if ($stockItem->getManageStock() && !$stockItem->checkQty($item->getQty()) && !$stockItem->getBackorders()) {
             $isBuyable = false;
             $error = array();
             $error['type'] = ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE;
             $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE);
             $errors[] = $error;
         } else {
             if ($stockItem->getManageStock() && $checkIncrements->getHasError()) {
                 $isBuyable = false;
                 $error = array();
                 $error['type'] = ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE;
                 $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE);
                 $errors[] = $error;
                 $stockItem->setQty((int) ($item->getQtyToAdd() / $stockItem->getQtyIncrements()) * $stockItem->getQtyIncrements());
             }
         }
     }
     $qtyBuyable = $isBuyable ? (int) $item->getQty() : (int) $stockItem->getQty();
     return Mage::helper('shopgate')->generateShopgateCartItem($product, $isBuyable, $qtyBuyable, $priceInclTax, $priceExclTax, $errors, (int) $stockItem->getQty());
 }
Example #2
0
 /**
  * Overwrite @method _addItemToQtyArray
  *
  * Adds stock item qty to $items (creates new entry or increments existing one)
  * $items is array with following structure:
  * array(
  *  $productId  => array(
  *      'qty'   => $qty,
  *      'item'  => $stockItems|null
  *  )
  * )
  *
  * @param Mage_Sales_Model_Quote_Item $quoteItem
  * @param array &$items
  */
 protected function _addItemToQtyArray($quoteItem, &$items)
 {
     $productId = $quoteItem->getProductId();
     if (!$productId) {
         return;
     }
     if (isset($items[$productId])) {
         $items[$productId]['qty'] += $quoteItem->getTotalQty();
     } else {
         $stockItem = null;
         if ($quoteItem->getProduct()) {
             $stockItem = $quoteItem->getProduct()->getStockItem();
         }
         $items[$productId] = array('item' => $stockItem, 'qty' => $quoteItem->getTotalQty(), 'quote_item_id' => $quoteItem->getId(), 'creditmemo_item_id' => null);
     }
 }
 /**
  * Test if the item needs to have its quantity checked for available
  * inventory.
  * @param  Mage_Sales_Model_Quote_Item $item The item to check
  * @return bool True if inventory is managed, false if not
  */
 public function isItemInventoried(Mage_Sales_Model_Quote_Item $item)
 {
     // never consider a child product as inventoried, allow the parent deal
     // with inventory and let the child not need to worry about it as the parent
     // will be the item to keep track of qty being ordered.
     // Both checks needed as child items will not have a parent item id prior
     // to being saved and a parent item prior to being added to the parent (e.g.
     // immediately after being loaded from the DB).
     if ($item->getParentItemId() || $item->getParentItem()) {
         return false;
     }
     // when dealing with parent items, if any child of the product is managed
     // stock, consider the entire item as managed stock - allows for the parent
     // config product in the quote to deal with inventory while allowing child
     // products to not care individually
     if ($item->getHasChildren()) {
         foreach ($item->getChildren() as $childItem) {
             $childStock = $childItem->getProduct()->getStockItem();
             if ($this->isManagedStock($childStock)) {
                 // This Parent is inventoried. Child's ROM setting is 'No backorders', and Manage Stock check hasn't been manually overridden
                 return true;
             }
         }
         // if none of the children were managed stock, the parent is not inventoried
         return false;
     }
     return $this->isManagedStock($item->getProduct()->getStockItem());
 }
Example #4
0
 /**
  * @param Mage_Sales_Model_Quote_Item $item
  * @return string
  */
 public function getItemEditOptionsHtml(Mage_Sales_Model_Quote_Item $item)
 {
     $product = $item->getProduct();
     $optionsBlock = $this->getLayout()->createBlock('emjainteractive_advancedoptions/catalog_product_view_options', 'product.info.options.' . $item->getId())->addOptionRenderer('file', 'emjainteractive_advancedoptions/catalog_product_view_options_type_text', 'emjainteractive/advancedoptions/catalog/product/view/options/type/text.phtml')->addOptionRenderer('select', 'emjainteractive_advancedoptions/catalog_product_view_options_type_select', 'emjainteractive/advancedoptions/catalog/product/view/options/type/select.phtml')->addOptionRenderer('date', 'emjainteractive_advancedoptions/catalog_product_view_options_type_date', 'emjainteractive/advancedoptions/catalog/product/view/options/type/date.phtml')->addOptionRenderer('text', 'emjainteractive_advancedoptions/catalog_product_view_options_type_text', 'emjainteractive/advancedoptions/catalog/product/view/options/type/text.phtml')->setTemplate('catalog/product/view/options.phtml')->setProduct($product)->setQuoteItem($item);
     $jsBlock = $this->getLayout()->createBlock('core/template', 'options_js' . $item->getId())->setTemplate('catalog/product/view/options/js.phtml');
     return $jsBlock->toHtml() . $optionsBlock->toHtml();
 }
Example #5
0
 /**
  * Get html for MAP product enabled
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return string
  */
 public function getMsrpHtml($item)
 {
     $product = $item->getProduct();
     $block = $this->_preparePriceBlock($product);
     $html = $block->setDisplayMinimalPrice(true)->toHtml();
     $product->setRealPriceHtml($html);
     return $this->_getPriceContent($product);
 }
 /**
  * Get html for MAP product enabled
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return string
  */
 public function getMsrpHtml($item)
 {
     $product = $item->getProduct();
     $block = $this->_preparePriceBlock($product);
     $html = $block->setPriceElementIdPrefix('bundle-price-')->toHtml();
     $product->setRealPriceHtml($html);
     return $this->_getPriceContent($product);
 }
Example #7
0
 public function getProduct()
 {
     $product = parent::getProduct();
     if (!$product->getTypeId()) {
         $product->setTypeId('simple');
     }
     return $product;
 }
Example #8
0
 public function importQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem)
 {
     $this->setQuoteItemId($quoteItem->getId())->setProductId($quoteItem->getProductId())->setProduct($quoteItem->getProduct())->setSuperProductId($quoteItem->getSuperProductId())->setSuperProduct($quoteItem->getSuperProduct())->setSku($quoteItem->getSku())->setImage($quoteItem->getImage())->setName($quoteItem->getName())->setDescription($quoteItem->getDescription())->setWeight($quoteItem->getWeight())->setPrice($quoteItem->getPrice())->setCost($quoteItem->getCost());
     if (!$this->hasQty()) {
         $this->setQty($quoteItem->getQty());
     }
     $this->setQuoteItemImported(true);
     return $this;
 }
Example #9
0
 /**
  * Validate stock of a quoteItem
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @param float                       $priceInclTax
  * @param float                       $priceExclTax
  * @return ShopgateCartItem $result
  */
 public function validateStock(Mage_Sales_Model_Quote_Item $item, $priceInclTax, $priceExclTax)
 {
     switch ($item->getProduct()->getTypeId()) {
         case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
             $model = Mage::getModel('shopgate/shopgate_cart_validation_stock_bundle');
             break;
         default:
             $model = Mage::getModel('shopgate/shopgate_cart_validation_stock_simple');
     }
     return $model->validateStock($item, $priceInclTax, $priceExclTax);
 }
Example #10
0
 /**
  * Get button to configure product
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return mixed
  */
 public function getConfigureButtonHtml($item)
 {
     $product = $item->getProduct();
     $options = array('label' => Mage::helper('sales')->__('Configure'));
     if ($product->canConfigure()) {
         $options['onclick'] = sprintf('orderEditItems.showQuoteItemConfiguration(%s)', $item->getId());
     } else {
         $options['class'] = ' disabled';
         $options['title'] = Mage::helper('sales')->__('This product does not have any configurable options');
     }
     return $this->getLayout()->createBlock('adminhtml/widget_button')->setData($options)->toHtml();
 }
Example #11
0
 /**
  * Validate stock of a quoteItem
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @param float                       $priceInclTax
  * @param float                       $priceExclTax
  *
  * @return ShopgateCartItem $result
  */
 public function validateStock(Mage_Sales_Model_Quote_Item $item, $priceInclTax, $priceExclTax)
 {
     $product = $item->getProduct();
     /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */
     $stockItem = $product->getStockItem();
     $errors = array();
     $isBuyable = true;
     $qtyBuyable = null;
     foreach ($item->getChildren() as $childItem) {
         /** @var Mage_Catalog_Model_Product $childProduct */
         $childProduct = $childItem->getProduct();
         /** @var Mage_CatalogInventory_Model_Stock_Item $childStock */
         $childStock = $childProduct->getStockItem();
         if ($childStock->getManageStock() && !$childProduct->isSaleable() && !$childStock->getBackorders()) {
             $isBuyable = false;
             $error = array();
             $error['type'] = ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK;
             $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK);
             $errors[] = $error;
         } else {
             if ($childStock->getManageStock() && !$childStock->checkQty($childItem->getQty()) && !$childStock->getBackorders()) {
                 $isBuyable = false;
                 $error = array();
                 $error['type'] = ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE;
                 $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE);
                 $errors[] = $error;
                 if ($qtyBuyable == null || $qtyBuyable > $childStock->getQty()) {
                     $qtyBuyable = $childStock->getQty();
                 }
             } else {
                 if (Mage::helper('shopgate/config')->getIsMagentoVersionLower1410()) {
                     $checkIncrements = Mage::helper('shopgate')->checkQtyIncrements($childStock, $childItem->getQty());
                 } else {
                     $checkIncrements = $childStock->checkQtyIncrements($childItem->getQty());
                 }
                 if ($childStock->getManageStock() && $checkIncrements->getHasError()) {
                     $isBuyable = false;
                     $error = array();
                     $error['type'] = ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE;
                     $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE);
                     $errors[] = $error;
                     $stockItem->setQty((int) ($item->getQtyToAdd() / $stockItem->getQtyIncrements()) * $stockItem->getQtyIncrements());
                 }
             }
         }
     }
     $qtyBuyable = $qtyBuyable == null ? (int) $item->getQty() : (int) $qtyBuyable;
     return Mage::helper('shopgate')->generateShopgateCartItem($product, $isBuyable, $qtyBuyable, $priceInclTax, $priceExclTax, $errors, (int) $stockItem->getQty());
 }
Example #12
0
 /**
  * @param Mage_Sales_Model_Quote_Item $recQuoteItem
  * @return mixed
  */
 public function getRecurringItemMessage(Mage_Sales_Model_Quote_Item $recQuoteItem)
 {
     $recurringItemMessage = '';
     $initialFeeMessage = '';
     $rowTotal = $recQuoteItem->getNominalRowTotal();
     $currency_symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
     $product = $recQuoteItem->getProduct();
     $productAdditionalInfo = unserialize($product->getCustomOption('info_buyRequest')->getValue());
     $deferredDateStamp = strtotime($productAdditionalInfo['recurring_profile_start_datetime']);
     if ($deferredDateStamp) {
         $initialFeeMessage = $this->__(" (initial fee only, 1st recurring fee will be charged on %s)", date('d-M-Y', $deferredDateStamp));
         $rowTotal = $recQuoteItem->getXpRecurringInitialFee() + $recQuoteItem->getInitialfeeTaxAmount();
     }
     $recurringItemMessage = $this->__("%s%s for recurring product '%s' in your cart.", number_format($rowTotal, 2, '.', ''), $currency_symbol, $recQuoteItem->getName());
     $mainMessage = $recurringItemMessage . $initialFeeMessage;
     return $mainMessage;
 }
Example #13
0
 /**
  * Generate serialized product options as in POST or GET parameters
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 public function getProductOptionsParameters(Mage_Sales_Model_Quote_Item $item)
 {
     $product = $item->getProduct();
     $options = $this->getProductOptions($item);
     $data = array();
     foreach ($options as $option) {
         $id = $option['option_id'];
         $objOption = $product->getOptionById($id);
         $objValues = $objOption->getValuesCollection()->getItems();
         $value = $this->_mapValueToOptionValue($option['value'], $objValues);
         // overwrite multi-options
         if (in_array($option['option_type'], array('multiple', 'checkbox'))) {
             $values = array_filter(explode(', ', $value));
             $value = array();
             foreach ($values as $optionId) {
                 $value[] = $this->_mapValueToOptionValue($optionId, $objValues);
             }
         }
         // overwrite date-time options
         if (in_array($option['option_type'], array('date_time', 'date', 'time'))) {
             $timestamp = strtotime($value);
             $value = array();
             if (in_array($option['option_type'], array('date_time', 'date'))) {
                 $value['month'] = date('n', $timestamp);
                 $value['day'] = date('j', $timestamp);
                 $value['year'] = date('Y', $timestamp);
             }
             if (in_array($option['option_type'], array('date_time', 'time'))) {
                 $value['hour'] = date('g', $timestamp);
                 $value['minute'] = ltrim(date('i', $timestamp), '0');
                 $value['minute'] = $value['minute'] ? $value['minute'] : '0';
                 $value['day_part'] = date('a', $timestamp);
             }
         }
         $data[$id] = $value;
     }
     return $data;
 }
Example #14
0
 /**
  * Add generate an array of product data
  *
  * @name generateProductData
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 public function generateProductData($item)
 {
     $orderOptions = array();
     $product = Mage::getModel('catalog/product')->load($item->getProductId());
     if ($product->getVisibility() == 1) {
         return null;
     }
     $productOptions = $item->getProductOptions();
     if (is_object($item->getProduct())) {
         $orderOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
     }
     $productData = $this->parseObject($product, 'addProduct');
     $itemData = $this->parseObject($item, 'addProduct');
     $itemData['variant'] = $this->extractAttributes($productOptions, $orderOptions);
     return array_filter(array_merge($productData, $itemData), 'strlen');
 }
Example #15
0
 /**
  * Prepare options array for info buy request
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 protected function _prepareOptionsForRequest($item)
 {
     $newInfoOptions = array();
     if ($optionIds = $item->getOptionByCode('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $option = $item->getProduct()->getOptionById($optionId);
             $optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
             $group = Mage::getSingleton('catalog/product_option')->groupFactory($option->getType())->setOption($option)->setQuoteItem($item);
             $newInfoOptions[$optionId] = $group->prepareOptionValueForRequest($optionValue);
         }
     }
     return $newInfoOptions;
 }
Example #16
0
 /**
  * Checks if item is configurable
  *
  * @param Mage_Sales_Model_Quote_Address_Item|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Creditmemo_Item|Mage_Sales_Model_Order_Invoice_Item $item
  * @return bool
  */
 protected function _isConfigurable($item)
 {
     if ($item instanceof Mage_Sales_Model_Quote_Item) {
         return $item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
     }
     if ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
         return $item->getProduct()->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
     }
     if ($item instanceof Mage_Sales_Model_Order_Invoice_Item || $item instanceof Mage_Sales_Model_Order_Creditmemo_Item) {
         return $item->getOrderItem()->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
     }
     return false;
 }
Example #17
0
 /**
  * Get html for MAP product enabled
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return string
  */
 public function getMsrpHtml($item)
 {
     return $this->getLayout()->createBlock('catalog/product_price')->setTemplate('catalog/product/price_msrp_item.phtml')->setProduct($item->getProduct())->toHtml();
 }
Example #18
0
 /**
  * Add new product to registry
  *
  * @param int|Mage_Sales_Model_Quote_Item $itemToAdd
  * @param Varien_Object $request
  * @return Enterprise_GiftRegistry_Model_Item
  */
 public function addItem($itemToAdd, $request = null)
 {
     if ($itemToAdd instanceof Mage_Sales_Model_Quote_Item) {
         $productId = $itemToAdd->getProductId();
         $qty = $itemToAdd->getQty();
     } else {
         $productId = $itemToAdd;
         $qty = $request && $request->getQty() ? $request->getQty() : 1;
     }
     $product = $this->getProduct($productId);
     if ($product->getTypeInstance(true)->hasRequiredOptions($product) && (!$request && !$itemToAdd instanceof Mage_Sales_Model_Quote_Item)) {
         throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS);
     }
     if ($itemToAdd instanceof Mage_Sales_Model_Quote_Item) {
         $cartCandidate = $itemToAdd->getProduct();
         $cartCandidate->setCustomOptions($itemToAdd->getOptionsByCode());
         $cartCandidates = array($cartCandidate);
     } else {
         if (!$request) {
             $request = new Varien_Object();
             $request->setBundleOption(array());
             //Bundle options mocking for compatibility
         }
         $cartCandidates = $product->getTypeInstance(true)->prepareForCart($request, $product);
     }
     if (is_string($cartCandidates)) {
         //prepare process has error, seems like we have bundle
         throw new Mage_Core_Exception($cartCandidates, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS);
     }
     $item = Mage::getModel('enterprise_giftregistry/item');
     $items = $item->getCollection()->addRegistryFilter($this->getId());
     foreach ($cartCandidates as $currentCandidate) {
         if ($currentCandidate->getParentProductId()) {
             continue;
         }
         $alreadyExists = false;
         $productId = $currentCandidate->getId();
         foreach ($items as $itemForCheck) {
             if ($itemForCheck->isRepresentProduct($currentCandidate)) {
                 $alreadyExists = true;
                 $matchedItem = $itemForCheck;
                 break;
             }
         }
         $candidateQty = $currentCandidate->getCartQty();
         if (!empty($candidateQty)) {
             $qty = $candidateQty;
         }
         if ($alreadyExists) {
             $matchedItem->setQty($matchedItem->getQty() + $qty)->save();
         } else {
             $customOptions = $currentCandidate->getCustomOptions();
             $item = Mage::getModel('enterprise_giftregistry/item');
             $item->setEntityId($this->getId())->setProductId($productId)->setOptions($customOptions)->setQty($qty)->save();
         }
     }
     return $item;
 }
Example #19
0
 /**
  * Adds stock item qty to $items (creates new entry or increments existing one)
  * $items is array with following structure:
  * array(
  *  $productId  => array(
  *      'qty'   => $qty,
  *      'item'  => $stockItems|null
  *  )
  * )
  *
  * @param Mage_Sales_Model_Quote_Item $quoteItem
  * @param array &$items
  */
 private function _addItemToQtyArray($quoteItem, &$items)
 {
     $productId = $quoteItem->getProductId();
     if (!$productId) {
         return;
     }
     if (isset($items[$productId])) {
         $items[$productId]['qty'] += $quoteItem->getTotalQty();
     } else {
         $stockItem = null;
         if ($quoteItem->getProduct()) {
             $stockItem = $quoteItem->getProduct()->getStockItem();
         }
         $items[$productId] = array('item' => $stockItem, 'qty' => $quoteItem->getTotalQty());
     }
 }
Example #20
0
 /**
  * Retrieve product identifier linked with item
  *
  * @param   Mage_Sales_Model_Quote_Item $item
  * @return  int
  */
 public function getProductId($item)
 {
     return $item->getProduct()->getId();
 }
 /**
  * Compare item
  *
  * @param   Mage_Sales_Model_Quote_Item $item
  * @return  bool
  */
 public function compare($item)
 {
     if ($this->getProductId() != $item->getProductId()) {
         return false;
     }
     foreach ($this->getOptions() as $option) {
         if (in_array($option->getCode(), $this->_notRepresentOptions) && !$item->getProduct()->hasCustomOptions()) {
             continue;
         }
         if ($itemOption = $item->getOptionByCode($option->getCode())) {
             $itemOptionValue = $itemOption->getValue();
             $optionValue = $option->getValue();
             // dispose of some options params, that can cramp comparing of arrays
             if (is_string($itemOptionValue) && is_string($optionValue)) {
                 try {
                     /** @var Unserialize_Parser $parser */
                     $parser = Mage::helper('core/unserializeArray');
                     $_itemOptionValue = $parser->unserialize($itemOptionValue);
                     $_optionValue = $parser->unserialize($optionValue);
                     if (is_array($_itemOptionValue) && is_array($_optionValue)) {
                         $itemOptionValue = $_itemOptionValue;
                         $optionValue = $_optionValue;
                         // looks like it does not break bundle selection qty
                         unset($itemOptionValue['qty'], $itemOptionValue['uenc']);
                         unset($optionValue['qty'], $optionValue['uenc']);
                     }
                 } catch (Exception $e) {
                     Mage::logException($e);
                 }
             }
             if ($itemOptionValue != $optionValue) {
                 return false;
             }
         } else {
             return false;
         }
     }
     return true;
 }
Example #22
0
 protected function getProductUrl(Mage_Sales_Model_Quote_Item $item)
 {
     if ($item->getRedirectUrl()) {
         return $item->getRedirectUrl();
     }
     $product = $item->getProduct();
     $option = $item->getOptionByCode('product_type');
     if ($option) {
         $product = $option->getProduct();
     }
     return $product->getUrlModel()->getUrl($product);
 }
 /**
  * Returns whether moving to wishlist is allowed for this item
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return bool
  */
 public function isMoveToWishlistAllowed($item)
 {
     return $item->getProduct()->isVisibleInSiteVisibility();
 }
Example #24
0
 /**
  * Check Quote item qty. If qty is not enougth for order, error flag and message added to $quote item
  *
  * @param Mage_Sales_Model_Quote_Item $quoteItem
  */
 protected function checkQuoteItemQty($quoteItem)
 {
     $qty = $quoteItem->getQty();
     if (($options = $quoteItem->getQtyOptions()) && $qty > 0) {
         $qty = $quoteItem->getProduct()->getTypeInstance(true)->prepareQuoteItemQty($qty, $quoteItem->getProduct());
         $quoteItem->setData('qty', $qty);
         foreach ($options as $option) {
             $optionQty = $qty * $option->getValue();
             $increaseOptionQty = ($quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty) * $option->getValue();
             $stockItem = $option->getProduct()->getStockItem();
             /* @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
             if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) {
                 $quoteItem->setHasError(true)->setMessage('Stock item for Product in option is not valid');
                 return;
             }
             $result = $stockItem->checkQuoteItemQty($optionQty, $optionQty, $option->getValue());
             if ($result->getHasError()) {
                 $quoteItem->setHasError(true)->setMessage($result->getQuoteMessage());
             }
         }
     } else {
         $stockItem = $quoteItem->getProduct()->getStockItem();
         /* @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
         if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) {
             Mage::throwException(Mage::helper('cataloginventory')->__('Stock item for Product is not valid'));
         }
         /**
          * When we work with subitem (as subproduct of bundle or configurable product)
          */
         if ($quoteItem->getParentItem()) {
             $rowQty = $quoteItem->getParentItem()->getQty() * $qty;
             /**
              * we are using 0 because original qty was processed
              */
             $qtyForCheck = 0;
         } else {
             $increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
             $rowQty = $qty;
             $qtyForCheck = $qty;
         }
         $result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty);
         if ($result->getHasError()) {
             $quoteItem->setHasError(true)->setMessage($result->getQuoteMessage());
         }
     }
 }
Example #25
0
 /**
  * Prepare options array for info buy request
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 protected function _prepareOptionsForRequest($item)
 {
     $newInfoOptions = array();
     if ($optionIds = $item->getOptionByCode('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $optionType = $item->getProduct()->getOptionById($optionId)->getType();
             $optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
             if ($optionType == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $optionType == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
                 $optionValue = explode(',', $optionValue);
             }
             $newInfoOptions[$optionId] = $optionValue;
         }
     }
     return $newInfoOptions;
 }
 /**
  * Check ability to display gift wrapping for quote item
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return bool
  */
 public function getDisplayGiftWrappingForItem($item)
 {
     $allowed = $item->getProduct()->getGiftWrappingAvailable();
     return Mage::helper('enterprise_giftwrapping')->isGiftWrappingAvailableForProduct($allowed, $this->getStoreId());
 }
Example #27
0
 /**
  * Check whether item link should be rendered
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return bool
  */
 public function showItemLink(Mage_Sales_Model_Quote_Item $item)
 {
     $product = $item->getProduct();
     if ($product->isComposite()) {
         $productsByGroups = $product->getTypeInstance(true)->getProductsToPurchaseByReqGroups($product);
         foreach ($productsByGroups as $productsInGroup) {
             foreach ($productsInGroup as $childProduct) {
                 if ($childProduct->hasStockItem() && $childProduct->getStockItem()->getIsInStock() && !$childProduct->isDisabled()) {
                     return true;
                 }
             }
         }
         return false;
     }
     return true;
 }
Example #28
0
 /**
  * Return vendor ID for quote item based on requested qty
  *
  * if $qty===true, always return dropship vendor id
  * if $qty===false, always return local vendor id
  * otherwise return local vendor if enough qty in stock
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @param integer|boolean $qty
  * @return integer
  * @deprecated since 1.6.0
  */
 public function getQuoteItemVendor($item, $qty = 0)
 {
     $product = $item->getProduct();
     if (!$product || !$product->hasUdropshipVendor()) {
         // if not available, load full product info to get product vendor
         $product = Mage::getModel('catalog/product')->load($item->getProductId());
     }
     $store = $item->getQuote() ? $item->getQuote()->getStore() : $item->getOrder()->getStore();
     $localVendorId = $this->getLocalVendorId($store);
     $vendorId = $product->getUdropshipVendor();
     // product doesn't have vendor specified OR force local vendor
     if (!$vendorId || $qty === false) {
         return $localVendorId;
     }
     // force real vendor
     if ($qty === true) {
         return $vendorId;
     }
     // local stock is available
     if (Mage::getSingleton('udropship/stock_availability')->getUseLocalStockIfAvailable($store, $vendorId) && $product->getStockItem()->checkQty($qty)) {
         return $localVendorId;
     }
     // all other cases
     return $vendorId;
 }
 /**
  * Get Custom Options of item
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 public function getCustomOptions(Mage_Sales_Model_Quote_Item $item)
 {
     $optionStr = '';
     $this->_moveToCustomerStorage = true;
     if ($optionIds = $item->getOptionByCode('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $item->getProduct()->getOptionById($optionId)) {
                 $optionValue = $item->getOptionByCode('option_' . $option->getId())->getValue();
                 $optionStr .= $option->getTitle() . ':';
                 $quoteItemOption = $item->getOptionByCode('option_' . $option->getId());
                 $group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
                 $optionStr .= $group->getEditableOptionValue($quoteItemOption->getValue());
                 $optionStr .= "\n";
             }
         }
     }
     return $optionStr;
 }
Example #30
0
 /**
  * Get Custom Options of item
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return array
  */
 public function getCustomOptions(Mage_Sales_Model_Quote_Item $item)
 {
     $optionStr = '';
     $this->_moveToCustomerStorage = true;
     if ($optionIds = $item->getOptionByCode('option_ids')) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             if ($option = $item->getProduct()->getOptionById($optionId)) {
                 $optionValue = $item->getOptionByCode('option_' . $option->getId())->getValue();
                 $optionStr .= $option->getTitle() . ':';
                 if ($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX || $option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE) {
                     foreach (explode(',', $optionValue) as $_value) {
                         $optionStr .= $option->getValueById($_value)->getTitle() . ', ';
                     }
                     $optionStr = Mage::helper('core/string')->substr($optionStr, 0, -2);
                 } elseif ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
                     $optionStr .= $option->getValueById($optionValue)->getTitle();
                 } else {
                     $optionStr .= $optionValue;
                 }
                 $optionStr .= "\n";
             }
         }
     }
     foreach ($item->getProduct()->getOptions() as $option) {
         if ($option->getIsRequire() && !$item->getOptionByCode('option_' . $option->getId())) {
             $optionStr .= $option->getTitle() . ':' . "\n";
         }
     }
     if ($additionalOptions = $item->getOptionByCode('additional_options')) {
         $this->_moveToCustomerStorage = false;
         foreach (unserialize($additionalOptions->getValue()) as $additionalOption) {
             $optionStr .= $additionalOption['label'] . ':' . $additionalOption['value'] . "\n";
         }
     }
     $optionStr = $this->helper('core/string')->substr($optionStr, 0, -1);
     return $optionStr;
 }