/** * @deprecated unused * Enter description here ... * @param unknown_type $observer */ public function payForShippingWithPoints($observer) { $this->setRequest($observer->getControllerAction()->getRequest()); $pay_for_shipping_with_points = $this->getRequest()->getParam('pay_for_shipping_with_points', ''); if ($pay_for_shipping_with_points) { $quote = Mage::getSingleton('rewards/session')->getQuote(); $shipaddr = $quote->getShippingAddress(); $total_shipping_value = $shipaddr->getShippingAmount(); $current_points_spending = Mage::getSingleton('rewards/session')->getPointsSpending(); Mage::log("Paying for shipping with points..."); $rule_ids = explode(',', $quote->getAppliedRedemptions()); foreach ($rule_ids as $rid) { $salesrule = Mage::helper('rewards/transfer')->getSalesRule($rid); if ($salesrule->getPointsAction() != 'discount_by_points_spent') { continue; } if (!$salesrule->getDiscountAmount()) { continue; } // discount amount should not be empty (so we dont divide by zero) Mage::log("Points step according to quote is {$quote->getPointsStep()}"); if ($salesrule->getPointsAmount() == $quote->getPointsStep()) { $uses_to_zero_shipping = ceil($total_shipping_value / $salesrule->getDiscountAmount()); Mage::getSingleton('rewards/session')->setPointsSpending($uses_to_zero_shipping + $current_points_spending); Mage::log("Added {$uses_to_zero_shipping} to existing points uage of {$current_points_spending}"); break; } } } return $this; }
/** * Attempts to retreive a product ID from the observer or the previously dispatch observer. * @param unknown_type $observer */ protected function _locatedProductId($observer) { $target_product_id = null; $event = $observer->getEvent(); $action = $observer->getControllerAction(); if ($action) { $request = $action->getRequest(); $target_product_id = $request->getParam("id"); if (!$target_product_id) { $target_product_id = null; } //if no product id available, reset our assumption because this must be some other unrecognized request. } $product = $observer->getProduct(); if (empty($product) && $event instanceof Varien_Event) { $product = $event->getProduct(); } if ($product) { $target_product_id = $product->getEntityId(); if (!$target_product_id) { $target_product_id = null; } } if ($target_product_id) { // IF a product ID was fetched, set it into the registry if (Mage::registry('rewards_catalogrule_apply_product_id_memory')) { Mage::unregister('rewards_catalogrule_apply_product_id_memory'); } Mage::register('rewards_catalogrule_apply_product_id_memory', $target_product_id); } else { // IF a product ID was NOT fetched, attempt to get it from the registry if (Mage::registry('rewards_catalogrule_apply_product_id_memory')) { $target_product_id = Mage::registry('rewards_catalogrule_apply_product_id_memory'); // After pulling it from the registry, remove it from the registry so the next immediate action does not recall this. Mage::unregister('rewards_catalogrule_apply_product_id_memory'); } } return $target_product_id; }
/** * Updates the points that you can use on products in the catalog afer product save events. * @param unknown_type $observer */ public function applyRulesOnProductAfterSave($observer) { $action = $observer->getControllerAction(); $request = $action->getRequest(); $product_id = $request->getParam("id"); $this->updateRulesHashOnProduct($product_id); return $this; }
/** * * Enter description here ... * @param unknown_type $o */ public function checkRedemptionCouponBefore($o) { $this->setRequest($o->getControllerAction()->getRequest()); $this->setResponse($o->getControllerAction()->getResponse()); $couponCode = (string) $this->getRequest()->getParam('coupon_code'); //@nelkaake Changed on Saturday July 17, 2010: $current_customer_group_id = Mage::getSingleton('rewards/session')->getCustomer()->getGroupId(); $current_website_id = Mage::app()->getStore()->getWebsiteId(); $rrs = Mage::getModel('rewards/salesrule_rule')->getCollection(); if (Mage::helper('rewards')->isBaseMageVersionAtLeast('1.4.1')) { $rrs->setValidationFilter($current_website_id, $current_customer_group_id, $couponCode); } else { $rrs->addFilter("coupon_code", $couponCode); } $rr = $rrs->getFirstItem(); $is_redem = Mage::getSingleton('rewards/salesrule_actions')->isRedemptionAction($rr->getPointsAction()); if ($is_redem) { if ($couponCode != $this->_getQuote()->getCouponCode()) { //applying redemption coupon $this->_redirect('rewards/cart_redeem/cartremove', array("rids" => $rr->getId())); } } return $this; }
/** * Base observer method that gets called by above observer methods whenever an account is being created in the frontend. * @param unknown_type $o * @param unknown_type $subfield * @throws Exception */ protected function attemptReferralCheck($o, $subfield = null) { try { //@nelkaake The customer is already logged in so there is no need to create referral links if (Mage::getSingleton('rewards/session')->isCustomerLoggedIn()) { return $this; } $code_field = 'rewards_referral'; $email_field = 'email'; $firstname_field = 'firstname'; $lastname_field = 'lastname'; $action = $o->getControllerAction(); $request = $action->getRequest(); $this->setRequest($request); $data = $request->getPost(); //@nelkaake Added on Thursday July 8, 2010: If a subfield (like billing) is needed, use it. if ($subfield) { if (isset($data[$subfield])) { $data = $data[$subfield]; } } //@nelkaake Added on Tuesday July 5, 2010: First some failsafe checks... if (empty($data)) { throw new Exception("Dispatched an event after the customer account creation method, " . 'but no data was found in app\\code\\community\\TBT\\RewardsReferral\\Model\\Observer\\Createaccount.php ' . "in TBT_RewardsReferral_Model_Observer_Createaccount::attemptReferralCheck.", 1); return $this; } //@nelkaake Added on Thursday July 8, 2010: Was a code and e-mail passed? //@nelkaake (add) on 1/11/10: By default, use the textbox code/email. $use_field = true; if (!isset($data[$code_field])) { $use_field = false; } else { if (empty($data[$code_field])) { $use_field = false; } } // If it's not set or if it's empty using the field, use the session if (!$use_field) { //@nelkaake Changed on Wednesday October 6, 2010: Change the code if the customer does if (Mage::helper('rewardsref/code')->getReferral()) { $data[$code_field] = Mage::helper('rewardsref/code')->getReferral(); } else { $data[$code_field] = ''; //throw new Exception("Customer signup was detected with data, but the '{$code_field}' field was not detected.", 1); } } // If all the possible referral code options are empty or not set, exit the registration system. if (empty($data[$code_field])) { return $this; } if (!isset($data[$email_field])) { throw new Exception("Customer signup was detected with data and the 'rewards_referral', but the '{$email_field}' field was not detected.", 1); } if (!isset($data[$firstname_field])) { Mage::helper('rewardsref')->log("Customer '{$firstname_field}' was not detected, but other data was detected."); $data[$firstname_field] = ' '; } if (!isset($data[$lastname_field])) { Mage::helper('rewardsref')->log("Customer '{$lastname_field}' was not detected, but other data was detected."); $data[$lastname_field] = ' '; } //@nelkaake Added on Thursday July 8, 2010: Fetchthe required data and load the customer $referral_code_or_email = $data[$code_field]; $new_customer_email = $data[$email_field]; //@nelkaake Added on Thursday July 8, 2010: We use this method of getting the full name becuase Magento has it's own getName() logic. $new_customer_name = Mage::getModel('customer/customer')->setFirstname($data[$firstname_field])->setLastname($data[$lastname_field])->getName(); // Let's make sure the referral entry is valid. $referral_email = Mage::helper('rewardsref/code')->parseEmailFromReferralString($referral_code_or_email); if ($referral_email == $new_customer_email) { throw new Exception("Customer with e-mail {$new_customer_email} tried to refer his/her self {$referral_email}.", 1); } Mage::helper('rewardsref/code')->setReferral($referral_code_or_email); Mage::helper('rewardsref')->initateSessionReferral2($new_customer_email, $new_customer_name); } catch (Exception $e) { Mage::helper('rewardsref')->log($e->getMessage()); if ($e->getCode() != 1) { Mage::logException($e); } } }