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

Multiple fixes and enhancements #41

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ This extension is maintained by [PHOENIX MEDIA](http://www.phoenix-media.eu/), M
Changelog
---------

1.0.14
- Fix issue #42: "foreigncosts" to "foreigncountrycosts" (Thanks to [sulabh](https://github.com/sulabh/Magento-CashOnDelivery/commit/c4bb65e374da3009cab92a982edad6b24e95ab88))

1.0.13
- Add locale "fr_FR" (Thanks to [MaWoScha](https://github.com/MaWoScha))
- Improve locale "it_IT" (Thanks to [emiliolodigiani](https://github.com/emiliolodigiani/Magento-CashOnDelivery/commit/0fe069c8af3645db16c12825c1d06642c580b312))

1.0.12
- "SR-714 allow capture offline" (Thanks to [Pascal Querner](https://github.com/MSCG/Magento-CashOnDelivery/commit/75475a11d647f8f14c9a4de0654b068f6a9d079a))
- Fixed "Display Zero Fee" in customer account order view" (Thanks to [idziakjakub](https://github.com/macopedia/Magento-CashOnDelivery/commit/ba0f39433f8cbae7cb79cd19a6da0c70d541e1c8) (#21))
- Add "cod_fee", "base_cod_fee" attributes to webservices (Thanks to [tawfekov](https://github.com/tawfekov/Magento-CashOnDelivery/commit/db91efdf110a1b9114e9d9e232925f20d382ae32) (#33))
- Update to better fit ECG/PSR-2 (Thanks to [sreichel](https://github.com/sreichel/Magento-CashOnDelivery/commit/bbaf06d84169675f6f84eba341e593265c9cf235))
- Removed not used observer method (Thanks to [sreichel](https://github.com/sreichel/Magento-CashOnDelivery/commit/89cbd3c2d464e900c1c1ac3e00cbc8f8a09cade7))
- Hide config options if module is disabled (Thanks to [sreichel](https://github.com/sreichel/Magento-CashOnDelivery/commit/a0ba5148f4f368fb4a553e416555ea10d213a0c6))
- Fixed "Add Create Invoice Option - Add ability to configure that a cash on delivery order automatically create an invoice." (Thanks to [Flipmediaco](https://github.com/Flipmediaco/Magento-CashOnDelivery/commit/8ae36cffd3bbab8e61852810c21a3c3a558378b4) (#19))

1.0.11
- Add locale "en_GB" and "pt_PT"
- Improve localization

1.0.10
- Implement issue #16: CoD refund now changeable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* COD fee Total Row Renderer
*
*
*/
class Phoenix_CashOnDelivery_Block_Adminhtml_Sales_Order_Create_Totals_Cod extends Mage_Adminhtml_Block_Sales_Order_Create_Totals_Default
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* COD fee Total Row Renderer
*
*
*/
class Phoenix_CashOnDelivery_Block_Checkout_Cod extends Mage_Checkout_Block_Total_Default
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Phoenix/CashOnDelivery/Block/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getShippingAddress()
return $this->getQuote()->getShippingAddress();
}

public function convertPrice($price, $format=false, $includeContainer = true)
public function convertPrice($price, $format = false, $includeContainer = true)
{
return $this->getQuote()->getStore()->convertPrice($price, $format, $includeContainer);
}
Expand Down
12 changes: 6 additions & 6 deletions app/code/community/Phoenix/CashOnDelivery/Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,26 @@ public function getRawCodFee()
public function getCodFeeExclTax()
{
if ($_dataObject = $this->_getDataObject()) {
$extraFeeExcl = $_dataObject->getCodFee() ? $this->_getPriceModel()->formatPrice($_dataObject->getCodFee()) : null;
return $extraFeeExcl;
if ($_dataObject->getCodFee()) {
return $this->_getPriceModel()->formatPrice($_dataObject->getCodFee());
}
}
return null;
}

public function getCodFeeInclTax()
{
if ($_dataObject = $this->_getDataObject()) {
$extraFeeIncl = $_dataObject->getCodFee() ? $this->_getPriceModel()->formatPrice($_dataObject->getCodFee()+$_dataObject->getCodTaxAmount()) : null;
return $extraFeeIncl;
if ($_dataObject->getCodFee()) {
return $this->_getPriceModel()->formatPrice($_dataObject->getCodFee() + $_dataObject->getCodTaxAmount());
}
}
return null;
}

protected function _getDataObject()
{
if (!isset($this->_dataObject)) {

$dataObject = $this->getInfo()->getQuote();

if (!is_object($dataObject)) {
Expand All @@ -81,7 +82,6 @@ protected function _getDataObject()
protected function _getPriceModel()
{
if (!isset($this->_priceModel)) {

$quote = $this->getInfo()->getQuote();
$priceModel = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function initTotals()
{
$this->_prepareTotals();

if ($this->_totalObject && $this->_totalObject->getCodFee()) {
if ($this->_totalObject && $this->_totalObject->getCodFee() && Mage::getStoreConfigFlag('payment/phoenix_cashondelivery/display_zero_fee')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work... If codFee check returns false the last && will not be validated. If the codFee Check returns true and display_zero_fee is set to false the total block is not added even if a fee is set.

$label = $this->__('Cash on Delivery fee');
$value = $this->_totalObject->getCodFee();
$baseValue = $this->_totalObject->getBaseCodFee();
Expand Down
14 changes: 7 additions & 7 deletions app/code/community/Phoenix/CashOnDelivery/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class Phoenix_CashOnDelivery_Helper_Data extends Mage_Core_Helper_Data
/**
* Config path constants
*/
const CONFIG_XML_PATH_COD_TAX_CLASS = 'tax/classes/phoenix_cashondelivery_tax_class';
const CONFIG_XML_PATH_COD_TAX_CLASS = 'tax/classes/phoenix_cashondelivery_tax_class';
const CONFIG_XML_PATH_COD_INCLUDES_TAX = 'tax/calculation/phoenix_cashondelivery_includes_tax';
const CONFIG_XML_PATH_DISPLAY_COD = 'tax/display/phoenix_cashondelivery_fee';
const CONFIG_XML_PATH_DISPLAY_COD = 'tax/display/phoenix_cashondelivery_fee';


/**
Expand Down Expand Up @@ -54,7 +54,7 @@ class Phoenix_CashOnDelivery_Helper_Data extends Mage_Core_Helper_Data
*/
public function codPriceIncludesTax($store = null)
{
$store = Mage::app()->getStore($store);
$store = Mage::app()->getStore($store);
$storeId = $store->getId();

if (!isset($this->_codPriceIncludesTax[$storeId])) {
Expand Down Expand Up @@ -139,10 +139,10 @@ public function getTotalAfterPosition()
{
if (!$this->_getTotalAfterPosition) {

$config = Mage::app()->getConfig()->getXpath('//sales/totals_sort');
$positions = end($config);
$positions = $positions->asArray();
$codPos = $positions['phoenix_cashondelivery'];
$config = Mage::app()->getConfig()->getXpath('//sales/totals_sort');
$positions = end($config);
$positions = $positions->asArray();
$codPos = $positions['phoenix_cashondelivery'];
$beforeTotal = 'subtotal';

asort($positions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ class Phoenix_CashOnDelivery_Model_CashOnDelivery extends Mage_Payment_Model_Met
protected $_code = 'phoenix_cashondelivery';
protected $_canUseForMultishipping = false;

protected $_canCapture = true;
protected $_canCapturePartial = true;

protected $_formBlockType = 'phoenix_cashondelivery/form';
protected $_infoBlockType = 'phoenix_cashondelivery/info';

protected $_costCalcBase = 'subtotal_incl_tax';
protected $_costCalcBase = 'subtotal_incl_tax';

/**
* Get the configured inland fee.
Expand All @@ -57,7 +60,7 @@ public function getInlandCosts($address = null)
*/
public function getForeignCountryCosts($address = null)
{
return $this->getCosts($address, 'foreigncosts');
return $this->getCosts($address, 'foreigncountrycosts');
}

/**
Expand All @@ -69,7 +72,7 @@ public function getForeignCountryCosts($address = null)
*/
public function getCosts($address, $type)
{
$cost = $this->getConfigData($type);
$cost = $this->getConfigData($type);
$minCost = $this->getConfigData("minimum_$type");

if (is_object($address) && Mage::getStoreConfigFlag(self::XML_CONFIG_PATH_CASHONDELIVERY_COST_TYPE)) {
Expand Down
72 changes: 41 additions & 31 deletions app/code/community/Phoenix/CashOnDelivery/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Phoenix_CashOnDelivery_Model_Observer extends Mage_Core_Model_Abstract
* @param Varien_Event_Observer $observer
* @return Phoenix_CashOnDelivery_Model_Observer
*/
public function sales_quote_collect_totals_after(Varien_Event_Observer $observer)
{
public function salesQuoteCollectTotalsAfter(Varien_Event_Observer $observer)
{
$quote = $observer->getEvent()->getQuote();
$data = $observer->getInput();

Expand All @@ -51,11 +51,11 @@ public function sales_quote_collect_totals_after(Varien_Event_Observer $observer
* @param Varien_Event_Observer $observer
* @return Phoenix_CashOnDelivery_Model_Observer
*/
public function sales_order_payment_place_end(Varien_Event_Observer $observer)
{
public function salesOrderPaymentPlaceEnd(Varien_Event_Observer $observer)
{
$payment = $observer->getPayment();
if ($payment->getMethodInstance()->getCode() != 'phoenix_cashondelivery') {
return $this;;
return $this;
}

$order = $payment->getOrder();
Expand All @@ -74,36 +74,13 @@ public function sales_order_payment_place_end(Varien_Event_Observer $observer)
return $this;
}

/**
* Performs order_create_loadBlock response update
* adds totals block to each response
* This function is deprecated, the totals block update is implemented
* in phoenix/cashondelivery/sales.js (SalesOrder class extension)
*
* @param Varien_Event_Observer $observer
* @return Phoenix_CashOnDelivery_Model_Observer
*/
public function controller_action_layout_load_before(Varien_Event_Observer $observer)
{
$action = $observer->getAction();

if ($action->getFullActionName() != 'adminhtml_sales_order_create_loadBlock' || !$action->getRequest()->getParam('json')) {
return $this;
}

$layout = $observer->getLayout();
$layout->getUpdate()->addHandle('adminhtml_sales_order_create_load_block_totals');

return $this;
}

/**
* When the order gets canceled we put the Cash on Delivery fee and tax also in the canceled columns.
*
* @param Varien_Event_Observer $observer
* @return Phoenix_CashOnDelivery_Model_Observer
*/
public function order_cancel_after(Varien_Event_Observer $observer)
public function orderCancelAfter(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getOrder();

Expand All @@ -116,7 +93,7 @@ public function order_cancel_after(Varien_Event_Observer $observer)
$codTax = $order->getCodTaxAmount();
$baseCodTax = $order->getBaseCodTaxAmount();

$codFeeInvoiced = $order->getCodFeeInvoiced();
$codFeeInvoiced = $order->getCodFeeInvoiced();

if ($codFeeInvoiced) {
$baseCodFeeInvoiced = $order->getBaseCodFeeInvoiced();
Expand All @@ -139,4 +116,37 @@ public function order_cancel_after(Varien_Event_Observer $observer)

return $this;
}
}


/**
* Invoice and set status to Cash On Delivery if order payment type is Cash on Delivery
*
* @author: https://github.com/Flipmediaco/Magento-CashOnDelivery/blob/8ae36cffd3bbab8e61852810c21a3c3a558378b4/app/code/community/Phoenix/CashOnDelivery/Model/Observer.php
* @param Varien_Event_Observer $observer
* @return void
*/
public function invoiceCashOnDelivery($observer)
{
// Get order
$order = $observer->getEvent()->getOrder();

// If order is instance of Phoenix_CashOnDelivery_Model_CashOnDelivery
if ($order->getPayment()->getMethodInstance()->getCode() == 'phoenix_cashondelivery' &&
// Can be invoiced
$order->canvoice() &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: canvoice() should be canInvoice()

// order_invoice is true
Mage::getStoreConfig('payment/phoenix_cashondelivery/order_invoice')) {
// Prepare invoice
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
// Set capture case - OFFLINE
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->register();
//
// Save transaction
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getTotalsForDisplay()
$fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
$helper = Mage::helper('phoenix_cashondelivery');

if ($helper->displayCodBothPrices()){
if ($helper->displayCodBothPrices()) {
$totals = array(
array(
'amount' => $this->getAmountPrefix().$amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function collect(Mage_Sales_Model_Quote_Address $address)
return $this;
}

$store = $address->getQuote()->getStore();
$store = $address->getQuote()->getStore();

$items = $address->getAllItems();
if (!count($items)) {
Expand Down Expand Up @@ -93,7 +93,7 @@ public function collect(Mage_Sales_Model_Quote_Address $address)
}

public function fetch(Mage_Sales_Model_Quote_Address $address)
{
{
$store = $address->getQuote()->getStore();
/**
* Modify subtotal
Expand All @@ -105,7 +105,7 @@ public function fetch(Mage_Sales_Model_Quote_Address $address)
} else {
$subtotalInclTax = $address->getSubtotal()+ $address->getTaxAmount() -
$address->getShippingTaxAmount() - $address->getCodTaxAmount();
}
}

$address->addTotal(
array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function collect(Mage_Sales_Model_Quote_Address $address)
return $this;
}

$baseTotal = $address->getBaseGrandTotal();
$baseTotal = $address->getBaseGrandTotal();

$baseCodFee = $paymentMethod->getAddressCodFee($address);

Expand All @@ -68,14 +68,14 @@ public function collect(Mage_Sales_Model_Quote_Address $address)
//Updating cod tax if it is already included into a COD fee
$baseCodTaxAmount = $paymentMethod->getAddressCodTaxAmount($address);
$address->setBaseCodTaxAmount($baseCodTaxAmount);
$address->setCodTaxAmount($store->convertPrice($baseCodTaxAmount, false));
$address->setCodTaxAmount($store->convertPrice($baseCodTaxAmount, false));

return $this;
}

public function fetch(Mage_Sales_Model_Quote_Address $address)
{
$amount = $address->getCodFee();
$amount = $address->getCodFee();
if ($amount!=0) {
$quote = $address->getQuote();
$address->addTotal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function toOptionArray()
{
$options = array();

foreach (Mage::app()->getStore()->getConfig('carriers') as $code => $carrier) {
foreach (Mage::app()->getStore()->getConfig('carriers') as $code => $carrier) {
if ($carrier['active'] && isset($carrier['title'])) {
$options[] = array(
'value' => $code,
Expand Down
Loading