Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to 'set' storeid for retrieving config #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/app/code/community/Brander/PaymentFee/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ public function isEnabled() {

/**
* Retrieve Store Config
*
* @param string $field
* @param null|int $storeId
* @return mixed|null
*/
public function getConfig($field = '') {
public function getConfig($field = '', $storeId=null) {
if ($field) {
return Mage::getStoreConfig(self::XML_PATH_SYSTEM_CONFIG . $field, $this->getCurrentStoreId());
if ($storeId ==null) {
$storeId = $this->getCurrentStoreId();
}
return Mage::getStoreConfig(self::XML_PATH_SYSTEM_CONFIG . $field, $storeId);
}

return NULL;
Expand All @@ -52,12 +57,14 @@ public function getFeeType() {

/**
* Retrieve and unserialize Payment Method and their Fees array from Store Config
*
* @param null|int $storeId
* @return array
*/
public function getFee() {
public function getFee($storeId = null) {
if (is_null($this->fee)) {
$fees = (array)unserialize($this->getConfig('fee'));
foreach ($fees as $fee) {
$fees = (array)unserialize($this->getConfig('fee', $storeId));
foreach ((array)$fees as $fee) {
$this->fee[$fee['payment_method']] = array(
'fee' => $fee['fee'],
'description' => $fee['description']
Expand Down
20 changes: 10 additions & 10 deletions src/app/code/community/Brander/PaymentFee/Model/Fee.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ class Brander_PaymentFee_Model_Fee extends Mage_Core_Model_Abstract {
*/
public $methodFee = NULL;

/**
* Constructor
*/
public function __construct() {
$this->_getMethodFee();
}

/**
* Retrieve Payment Method Fees from Store Config
*
* @param null|int $storeId
* @return array
*/
protected function _getMethodFee() {
protected function _getMethodFee($storeId = null) {
if (is_null($this->methodFee)) {
$this->methodFee = Mage::helper('payment_fee')->getFee();
$this->methodFee = Mage::helper('payment_fee')->getFee($storeId);
}

return $this->methodFee;
Expand Down Expand Up @@ -73,6 +68,8 @@ public function getFee(Mage_Sales_Model_Quote_Address $address) {
/* @var $quote Mage_Sales_Model_Quote */
$quote = $address->getQuote();
$method = $quote->getPayment()->getMethod();

$this->_getMethodFee($quote->getStoreId());
$fee = $this->methodFee[$method]['fee'];
$feeType = $helper->getFeeType();
if ($feeType == Mage_Shipping_Model_Carrier_Abstract::HANDLING_TYPE_FIXED) {
Expand Down Expand Up @@ -101,6 +98,9 @@ public function getTotalTitle($method = '', Mage_Sales_Model_Quote $quote = null
if (!$method) {
$method = $quote->getPayment()->getMethod();
}

$this->_getMethodFee($quote->getStoreId());

if ($method) {
if (isset($this->methodFee[$method]) && $this->methodFee[$method]['description']) {
$title = $this->methodFee[$method]['description'];
Expand All @@ -114,4 +114,4 @@ public function getTotalTitle($method = '', Mage_Sales_Model_Quote $quote = null

return $title;
}
}
}