Skip to content

Insurance extension #2

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

Open
wants to merge 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

class Itransition_Insurance_Block_Admin_Total_SalesOrder extends Mage_Adminhtml_Block_Sales_Order_Totals
{
protected $_code = 'insurance';

protected function _initTotals()
{
parent::_initTotals();
$order = $this->getOrder();
$amount = $order->getInsurance();
$insuranceLabel = Mage::getStoreConfig('insurance_options/customins/insurance_label');

$this->addTotalBefore(
new Varien_Object(
[
'code' => $this->getCode(),
'value' => $amount,
'base_value' => $amount,
'label' => Mage::helper('insurance')->__($insuranceLabel),
],
'grand_total'
)
);

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

class Itransition_Insurance_Block_Admin_Total_SalesOrderCreditmemo extends Mage_Adminhtml_Block_Sales_Order_Creditmemo_Totals
{
protected $_code = 'insurance';

protected function _initTotals()
{
parent::_initTotals();
$order = $this->getOrder();
$amount = $order->getInsurance();
$insuranceLabel = Mage::getStoreConfig('insurance_options/customins/insurance_label');

$this->addTotalBefore(
new Varien_Object(
[
'code' => $this->getCode(),
'value' => $amount,
'base_value' => $amount,
'label' => Mage::helper('insurance')->__($insuranceLabel),
],
'grand_total'
)
);

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

class Itransition_Insurance_Block_Admin_Total_SalesOrderInvoice extends Mage_Adminhtml_Block_Sales_Order_Invoice_Totals
{
protected $_code = 'insurance';

protected function _initTotals()
{
parent::_initTotals();
$order = $this->getOrder();
$amount = $order->getInsurance();
$insuranceLabel = Mage::getStoreConfig('insurance_options/customins/insurance_label');

$this->addTotalBefore(
new Varien_Object(
[
'code' => $this->getCode(),
'value' => $amount,
'base_value' => $amount,
'label' => Mage::helper('insurance')->__($insuranceLabel),
],
'grand_total'
)
);

return $this;
}
}
25 changes: 25 additions & 0 deletions app/code/local/Itransition/Insurance/Block/Onepage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class Itransition_Insurance_Block_Onepage extends Mage_Checkout_Block_Onepage
{
public function getSteps()
{
$steps = array();

if (!$this->isCustomerLoggedIn()) {
$steps['login'] = $this->getCheckout()->getStepData('login');
}

if (Mage::helper('insurance')->isEnabled()) {
$stepCodes = array('billing', 'shipping', 'shipping_method', 'insurance', 'payment', 'review');
}
else {
$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'review');
}
foreach ($stepCodes as $step) {
$steps[$step] = $this->getCheckout()->getStepData($step);
}

return $steps;
}
}
16 changes: 16 additions & 0 deletions app/code/local/Itransition/Insurance/Block/Onepage/Insurance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

class Itransition_Insurance_Block_Onepage_Insurance extends Mage_Checkout_Block_Onepage_Abstract
{
public function _construct()
{
parent::_construct();
$insuranceLabel = Mage::getStoreConfig('insurance_options/customins/insurance_label');

$this->getCheckout()->setStepData('insurance', array(
'label' => Mage::helper('insurance')->__($insuranceLabel),
'is_show' => true
));

}
}
27 changes: 27 additions & 0 deletions app/code/local/Itransition/Insurance/Block/Total/SalesOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

class Itransition_Insurance_Block_Total_SalesOrder extends Mage_Sales_Block_Order_Totals
{
protected $_code = 'insurance';

protected function _initTotals()
{
parent::_initTotals();
$order = $this->getOrder();
$amount = $order->getInsurance();
$insuranceLabel = Mage::getStoreConfig('insurance_options/customins/insurance_label');
$this->addTotalBefore(
new Varien_Object(
[
'code' => $this->getCode(),
'value' => $amount,
'base_value' => $amount,
'label' => $this->helper('insurance')->__($insuranceLabel)
],
'grand_total'
)
);

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

class Itransition_Insurance_Block_Total_SalesOrderCreditmemo extends Mage_Sales_Block_Order_Creditmemo_Totals
{
protected $_code = 'insurance';

protected function _initTotals()
{
parent::_initTotals();
$order = $this->getOrder();
$amount = $order->getInsurance();
$insuranceLabel = Mage::getStoreConfig('insurance_options/customins/insurance_label');

$this->addTotalBefore(
new Varien_Object(
[
'code' => $this->getCode(),
'value' => $amount,
'base_value' => $amount,
'label' => $this->helper('insurance')->__($insuranceLabel)
],
'grand_total'
)
);

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

class Itransition_Insurance_Block_Total_SalesOrderInvoice extends Mage_Sales_Block_Order_Invoice_Totals
{
protected $_code = 'insurance';

protected function _initTotals()
{
parent::_initTotals();
$order = $this->getOrder();
$amount = $order->getInsurance();
$insuranceLabel = Mage::getStoreConfig('insurance_options/customins/insurance_label');

$this->addTotalBefore(
new Varien_Object(
[
'code' => $this->getCode(),
'value' => $amount,
'base_value' => $amount,
'label' => $this->helper('insurance')->__($insuranceLabel)
],
'grand_total'
)
);

return $this;
}
}
48 changes: 48 additions & 0 deletions app/code/local/Itransition/Insurance/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

class Itransition_Insurance_Helper_Data extends Mage_Core_Helper_Abstract {
const XML_CONFIG_PATH = 'insurance_options/customins/';
public function isEnabled()
{
return (bool) $this->_getConfigValue('insurance_enable');
}
protected function _getConfigValue($key)
{
return Mage::getStoreConfig(self::XML_CONFIG_PATH . $key);
}

public function getRate()
{
$rateData = $this->getRateInfo();

if ($rateData['type'] == 2) {
return $rateData['rate'].'%';
}

$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$symbol = Mage::app()->getLocale()->currency($currency_code)->getSymbol();

return $rateData['rate'].$symbol;
}

public function getRateInfo()
{
$rate = $this->_getConfigValue('insurance_rate');
$type = $this->_getConfigValue('insurace_type');
$data = array(
'rate' => $rate,
'type' => $type
);

return $data;
}

public function isInsuranceEnabled()
{
$isEnabled = $this->isEnabled();
$isSelectedEnsurance = (bool) Mage::getSingleton('checkout/session')->getData('isSelectedInsurance', false);

return $isEnabled && $isSelectedEnsurance;
}

}
17 changes: 17 additions & 0 deletions app/code/local/Itransition/Insurance/Model/Enabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class Itransition_Insurance_Model_Enabled extends Mage_Core_Model_Config_Data
{
/**
* Provide available options as a value/label array
*
* @return array
*/
public function toOptionArray()
{
return array(
array('value'=>0, 'label'=>'Disabled'),
array('value'=>1, 'label'=>'Enabled'),
);
}
}
10 changes: 10 additions & 0 deletions app/code/local/Itransition/Insurance/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class Itransition_Insurance_Observer {

public function saveOrder(Varien_Event_Observer $observer)
{


}
}
17 changes: 17 additions & 0 deletions app/code/local/Itransition/Insurance/Model/Options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class Itransition_Insurance_Model_Options extends Mage_Core_Model_Config_Data
{
/**
* Provide available options as a value/label array
*
* @return array
*/
public function toOptionArray()
{
return array(
array('value'=>1, 'label'=>'Fixed rate'),
array('value'=>2, 'label'=>'% Percent rate')
);
}
}
27 changes: 27 additions & 0 deletions app/code/local/Itransition/Insurance/Model/Rate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

class Itransition_Insurance_Model_Rate extends Mage_Core_Model_Config_Data
{
public function save()
{
$value = $this->getValue();
$rate_type =Mage::app()->getRequest()->getParam('groups');
$rate_type = $rate_type['customins']['fields']['insurace_type']['value'];
$isValid = true;


if (!is_numeric($value) || $value <= 0) {
$isValid = false;
}
if ($rate_type == 2 && $value > 100) {
$isValid = false;
}

if (!$isValid) {
Mage::getSingleton('core/session')->addError('Rate value is not valid.');
return false;
}

return parent::save();
}
}
16 changes: 16 additions & 0 deletions app/code/local/Itransition/Insurance/Model/Total/Creditmemo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
class Itransition_Insurance_Model_Total_Creditmemo extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
{
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
$order = $creditmemo->getOrder();
$amount = $order->getInsurance();

if (Mage::helper('insurance')->isEnabled()) {
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $amount);
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $amount);
}

return $this;
}
}
19 changes: 19 additions & 0 deletions app/code/local/Itransition/Insurance/Model/Total/Invoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

class Itransition_Insurance_Model_Total_Invoice extends Mage_Sales_Model_Order_Invoice_Total_Abstract
{
public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{
$order = $invoice->getOrder();
$amount = $order->getInsurance();

if ( Mage::helper('insurance')->isEnabled() ) {
$invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
$invoice->setBaseGrandTotal(
$invoice->getBaseGrandTotal() + $amount
);
}

return $this;
}
}
Loading