Esempio n. 1
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;
 }
 /**
  * Returns the item's original price that includes tax
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @return double
  */
 public function displayOriginalPriceInclTax($item)
 {
     $tax = 0;
     if ($item->getTaxPercent()) {
         $tax = $item->getPrice() * ($item->getTaxPercent() / 100);
     }
     return $this->convertPrice($item->getPrice() + $tax / $item->getQty());
 }
Esempio n. 3
0
 /**
  * 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;
 }