/** * Do the points transfer for the review * * @param TBT_Rewards_Model_Customer $customer * @param int $rule Special Rule * @return boolean whether or not the point-transfer succeeded */ public function transferBirthdayPoints($customer, $rule) { $currencyId = $rule->getPointsCurrencyId(); $pointAmount = $rule->getPointsAmount(); $customerId = $customer->getId(); //$ruleId = $rule->getId(); $transfercomment = $this->getTransferComment(); $transferStatus = $this->getInitialTransferStatus(); $transfer = $this->create($customerId, $pointAmount, $currencyId, $transfercomment, $transferStatus); return null != $transfer; }
/** * * @param type $template * @param TBT_Rewards_Model_Customer $customer * @param type $pointsString * @return boolean send successful? */ public function sendEmail($customer, $pointsString, $date, $template) { /* @var $translate Mage_Core_Model_Translate */ $translate = Mage::getSingleton('core/translate'); $translate->setTranslateInline(false); /* @var $email Mage_Core_Model_Email_Template */ $email = Mage::getModel('core/email_template'); $sender = array('name' => strip_tags(Mage::helper('rewards/expiry')->getSenderName($customer->getStoreId())), 'email' => strip_tags(Mage::helper('rewards/expiry')->getSenderEmail($customer->getStoreId()))); $email->setDesignConfig(array('area' => 'frontend', 'store' => $customer->getStoreId())); $vars = array('customer_name' => $customer->getName(), 'customer_email' => $customer->getEmail(), 'store_name' => $customer->getStore()->getName(), 'points_transfered' => $pointsString, 'points_balance' => (string) $customer->getPointsSummary()); $email->sendTransactional($template, $sender, $customer->getEmail(), $customer->getName(), $vars); $translate->setTranslateInline(true); return $email->getSentSuccess(); }
/** * * @param TBT_Rewards_Model_Customer $customer * @return boolean */ public function maxLikesReached($customer) { $max_likes = Mage::helper('rewardssocial/facebook_config')->getMaxLikeRewardsPerDay($customer->getStore()); $current_time = time(); $h24 = 60 * 60 * 24; $oldest_req_time = $current_time - $h24; $all_likes_since_time = Mage::getModel('rewardssocial/facebook_like')->getCollection()->addFilter('customer_id', $customer->getId())->addFieldToFilter('UNIX_TIMESTAMP(created_time)', array('gteq' => $oldest_req_time)); if ($all_likes_since_time->count() > $max_likes) { return true; } $like_transfers = Mage::getResourceModel('rewardssocial/facebook_like_transfer_collection')->filterCustomerRewardsSince($customer->getId(), $oldest_req_time); if ($like_transfers->load()->count() > $max_likes) { return true; } return false; }
protected function getTotalPointsSpentInLast365Days(TBT_Rewards_Model_Customer $c) { $yearStart = date("Y-m-d", time() - self::SECS_IN_YEAR); // get current year $filteredTransferes = $c->getCustomerPointsCollectionAll()->addFieldToFilter("quantity", array('lt' => 0))->addFieldToFilter("creation_ts", array('gteq' => $yearStart))->addFieldToFilter("reason_id", array('eq' => TBT_Rewards_Model_Transfer_Reason::REASON_CUSTOMER_REDEMPTION))->addFieldToFilter("customer_id", $c->getId()); $points_spent = $filteredTransferes->sumPoints()->getFirstItem()->getPointsCount(); return $points_spent; }
/** * Fetches redemption catalog rules for this products * * @param TBT_Rewards_Model_Customer $customer * @return array */ public function getCatalogRedemptionRules($customer) { $datetime = Mage::helper('rewards')->now(); $wId = Mage::app()->getStore(true)->getWebsiteId(); if ($customer) { $gId = $customer->getGroupId(); } else { $gId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID; } $rule_array = $this->getApplicableCatalogRules($datetime, $wId, $gId); return $rule_array; }
/** * * @param Mage_Core_Model_Store $store * @param TBT_Rewards_Model_Catalog_Product $product * @param TBT_Rewards_Model_Customer $customer * @param float $redeemable_price * */ public function getPointSliderSettings($store, $product, $customer, $price) { try { if (!$this->getId()) { throw new Exception("Bad rule ID"); } if (!$product->getId()) { throw new Exception("Product ID provided does not exist"); } $redeem_price_per_usage = $price - Mage::helper('rewards')->priceAdjuster($price, $this->getEffect(), false, false); $redeemable_price = $price; // limit $redeemable_price to the redeem_percentage_price limit if ($this['points_max_redeem_percentage_price']) { $redeemable_price = $price * (min($this['points_max_redeem_percentage_price'], 100) / 100); } // find the number of redeem_usages needed to get the full product free $max_redeem_usage = $redeemable_price / $redeem_price_per_usage; // HACK: to keep none hole usage percent $max_redeem_usage_part = $max_redeem_usage; if ($max_redeem_usage > (int) $max_redeem_usage) { $max_redeem_usage = (int) $max_redeem_usage + 1; } // set of max points that can be used $points_max_set = array(); $points_max_set[] = $this['points_amount'] * $max_redeem_usage; if ($this['points_max_qty'] > 0) { $points_max_set[] = $this['points_max_qty']; } if ($customer != null && Mage::getSingleton('rewards/session')->isCustomerLoggedIn()) { $points_max_set[] = $customer->getUsablePointsBalance($this->getPointsCurrencyId()); } if (Mage::helper('rewards/config')->canUseRedemptionsIfNotLoggedIn() == false && Mage::getSingleton('rewards/session')->isCustomerLoggedIn() == false) { $points_max_set[] = 0; } // set of max usage that can be used $usage_max_set = array(); $usage_max_set[] = $max_redeem_usage; $usage_max_set[] = (int) (min($points_max_set) / $this['points_amount']); if ($this['points_uses_per_product'] > 0) { $usage_max_set[] = $this['points_uses_per_product']; } // set of max redeem price $redeem_price_max_set = array(); $redeem_price_max_set[] = $redeemable_price; $redeem_price_max_set[] = max($usage_max_set) * $redeem_price_per_usage; // --------- min $usage_min_set = array(); $usage_min_set[] = 0; $rRule = array(); // HACK: to keep none hole usage percent $rRule['on_price'] = $price; $rRule['max_redeem_usage_part'] = $max_redeem_usage_part; // TODO - admin option to change redeemer type $rRule['redeam_type'] = 'slider'; if ($this['points_uses_per_product'] == 1) { $rRule['redeam_type'] = 'once_per_product'; } //$rRule['effect_type'] = $rule->getPointsCatalogruleSimpleAction(); //$rRule['effect'] = $rule->getEffect(); //$rRule['can_use_rule'] = Mage::getSingleton('rewards/session')->isCustomerLoggedIn() || Mage::helper('rewards/config')->canUseRedemptionsIfNotLoggedIn(); $rRule['points_per_usage'] = $this['points_amount']; $rRule['points_spend_min'] = 0; $rRule['points_spend_max'] = min($points_max_set); $rRule['usage_min'] = max($usage_min_set); // mostly 0 $rRule['usage_max'] = min($usage_max_set); // the min of all the max $rRule['redeem_price_per_usage'] = $redeem_price_per_usage; $rRule['redeem_price_min'] = 0; $rRule['redeem_price_max'] = min($redeem_price_max_set); $rRule['rule_id'] = $this->getId(); $rRule['product_id'] = $product->getId(); $rRule['currency_id'] = $this->getPointsCurrencyId(); $rRule['name'] = $this->getName(); $rRule['currency_id'] = $this->getPointsCurrencyId(); // [TBT_Rewards_Model_Catalogrule_Rule::POINTS_CURRENCY_ID]; $rRule['points'] = Mage::helper('rewards/currency')->formatCurrency($rRule['points_per_usage'], $rRule['currency_id']); // $rRule['points_caption'] = Mage::helper('rewards')->getPointsString(array( // $rRule['currency_id'] => $rRule['points_per_usage'] // )); return $rRule; } catch (Exception $e) { // TODO FIX LOG ERROR Mage::log($e->getMessage()); //die("Error: " . $e->getMessage()); return null; } }
/** * Returns true if customerId is within the customer groups listed * @param TBT_Rewards_Model_Customer $customer : current customer id * @param array $groupIds : customer group ids array * * @return boolean */ protected function isInGroup($customer, array $groupIds) { $group_id = $customer->getGroupId(); return array_search($group_id, $groupIds) !== false; }