/** * 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; }
/** * Retenders the item's redemption rules and final row total and returns it. * @param Mage_Sales_Model_Quote_Item $item * @return array a map of the new item redemption data: * array('redemptions_data'=>{...}, 'row_total'=>float) */ protected function getUpdatedRedemptionData($item, $do_incl_tax = true) { // Step 1: Create a map of usability for all applied redemptions //echo "$item->getRedeemedPointsHash()"; $redeemed_points = Mage::helper('rewards')->unhashIt($item->getRedeemedPointsHash()); // Prepare data from item and initalize counters if ($item->getQuote()) { $store_currency = round($item->getQuote()->getStoreToQuoteRate(), 4); } if ($item->getOrder()) { $store_currency = round($item->getOrder()->getStoreToQuoteRate(), 4); } if ($item->hasCustomPrice()) { $product_price = (double) $item->getCustomPrice() * $store_currency; } else { //@nelkaake -a 17/02/11: We need to use our own calculation because the one that was set by the // rest of the Magento system is rounded. if (Mage::helper('tax')->priceIncludesTax() && $item->getPriceInclTax()) { $product_price = $item->getPriceInclTax() / (1 + $item->getTaxPercent() / 100); } else { $product_price = (double) $item->getPrice() * $store_currency; } } if ($item->getParentItem() || sizeof($redeemed_points) == 0) { return array('redemptions_data' => array(), 'row_total_incl_tax' => $item->getRowTotalInclTax(), 'row_total' => $item->getRowTotal()); } $total_qty = $item->getQty(); $total_qty_redeemed = 0.0; $row_total = 0.0; $new_redeemed_points = array(); $ret = array(); // Loop through and apply all our rules. foreach ($redeemed_points as $key => &$redemption_instance) { $redemption_instance = (array) $redemption_instance; $applic_qty = $redemption_instance[self::POINTS_APPLICABLE_QTY]; $rule_id = $redemption_instance[self::POINTS_RULE_ID]; $effect = $redemption_instance[self::POINTS_EFFECT]; $uses = isset($redemption_instance[self::POINTS_USES]) ? (int) $redemption_instance[self::POINTS_USES] : 1; $rule = Mage::helper('rewards/rule')->getCatalogRule($rule_id); // If a rule was turned off at some point in the back-end it should be removed and not calculated in the cart anymore. if (!$rule->getIsActive()) { $this->removeCatalogRedemptionsFromItem($item, array($rule_id)); $effect = ""; } $total_qty_remain = $total_qty - $total_qty_redeemed; if ($total_qty_remain > 0) { if ($total_qty_remain < $applic_qty) { $applic_qty = $total_qty_remain; $redemption_instance[TBT_Rewards_Model_Redeem::POINTS_APPLICABLE_QTY] = $applic_qty; } $price_after_redem = $this->getPriceAfterEffect($product_price, $effect, $item); $row_total += $applic_qty * (double) $price_after_redem; $total_qty_redeemed += $applic_qty; $new_redeemed_points[] = $redemption_instance; } else { $redemption_instance[TBT_Rewards_Model_Catalogrule_Rule::POINTS_APPLICABLE_QTY] = 0; $redemption_instance[TBT_Rewards_Model_Catalogrule_Rule::POINTS_USES] = 1; // used once by default unset($redeemed_points[$key]); } } $ret['redemptions_data'] = $new_redeemed_points; // Add in the left over products that perhaps weren't affected by qty adjustment. $total_qty_remain = $total_qty - $total_qty_redeemed; if ($total_qty_remain < 0) { $total_qty_remain = 0; $total_qty_redeemed = $total_qty; //throw new Exception("Redemption rules may be overlapping. Please notify the store administrator of this error."); } $row_total += $total_qty_remain * (double) $product_price; $ret['row_total'] = $row_total; $ret['row_total_incl_tax'] = $row_total * (1 + $item->getTaxPercent() / 100); return $ret; }