Beispiel #1
0
 /**
  * @param Mage_Sales_Model_Quote_Item $lineItem
  * @param Vbw_Punchout_Model_Sales_Stash $stash
  * @param Mage_Checkout_Model_Cart $cartObj
  * @param $options
  */
 public function unstashLineItemData($lineItem, $stash, $cartObj, $options)
 {
     $customData = Mage::getStoreConfig('vbw_punchout/order/stash_item_list');
     $customData = unserialize($customData);
     if (!empty($customData)) {
         foreach ($customData as $datum) {
             $info = $stash->stash($datum['key']);
             if (!empty($info) || is_numeric($info)) {
                 if (preg_match('/^([^\\/]+)\\/([^\\/]+)$/', $datum['key'], $s)) {
                     $src = $s[1];
                     $code = $s[2];
                     switch ($src) {
                         case "option":
                             $option = array('code' => $code, 'value' => $info);
                             $lineItem->addOption($option);
                     }
                 } else {
                     $lineItem->setData($datum['key'], $info);
                 }
             }
         }
     }
     Mage::dispatchEvent('punchout_cart_item_unstash', array('stash_item' => $stash, 'item' => $lineItem, 'cart' => $cartObj, 'options' => $options));
     Mage::helper('vbw_punchout')->debug('unstash item ' . print_r(Mage::helper('vbw_punchout/debug')->debugData($lineItem->getData()), true));
 }
Beispiel #2
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());
         }
     }
 }
 /**
  * Loads all relevant product and category data for the item
  *
  * @param  Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $item
  * @param  int $orderStoreId
  * @param  int $websiteId
  * @param  int $maxLimit
  */
 public function loadCatalogData($item, $storeId, $websiteId, $maxLimit = 10)
 {
     $product = null;
     $categories = array();
     $related = array();
     $upsells = array();
     // load product details
     if ($item->getProductId()) {
         $product = Mage::getModel('catalog/product')->load($item->getProductId());
         // deleted
         if (!$product->getId()) {
             $product = null;
         }
         if ($product) {
             $relatedCollection = $product->getRelatedProductCollection()->addAttributeToSelect('name')->addAttributeToSelect('sku')->addAttributeToSelect('url_path')->addAttributeToSelect('image')->addAttributeToSelect('visibility')->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setPageSize($maxLimit);
             foreach ($relatedCollection as $p) {
                 $websiteIds = $p->getWebsiteIds();
                 if (in_array($websiteId, $websiteIds)) {
                     $related[$p->getId()] = $this->convertAttributeData($p);
                 }
             }
             $upsellCollection = $product->getUpSellProductCollection()->addAttributeToSelect('name')->addAttributeToSelect('sku')->addAttributeToSelect('url_path')->addAttributeToSelect('image')->addAttributeToSelect('visibility')->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setPageSize($maxLimit);
             foreach ($upsellCollection as $p) {
                 $websiteIds = $p->getWebsiteIds();
                 if (in_array($websiteId, $websiteIds)) {
                     $upsells[$p->getId()] = $this->convertAttributeData($p);
                 }
             }
             $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name')->addAttributeToSelect('is_active')->addAttributeToSelect('url_path')->addAttributeToFilter('level', array('gt' => 1))->setPageSize($maxLimit);
             foreach ($categoryCollection as $category) {
                 $storeIds = $category->getStoreIds();
                 if (in_array($storeId, $storeIds)) {
                     $categories[$category->getId()] = $this->convertAttributeData($category);
                 }
             }
             $product->setRelatedProducts($related);
             $product->setUpSellProducts($upsells);
         }
         $item->setData('product', $product);
         $item->setCategories($categories);
     }
 }