Version Notes
Supported Magento 1.5.0.0 - 1.7.x, Magento Enterprise 1.8-1.12.x
Download this release
Release Info
| Developer | Exactor, Inc. |
| Extension | Mage_Exactor_Tax |
| Version | 2012.11.12 |
| Comparing to | |
| See all releases | |
Code changes from version 2012.10.19 to 2012.11.12
- app/code/local/Exactor/ExactorSettings/sql/ExactorSettings_setup/mysql4-install-14.04.2012.php +0 -1
- app/code/local/Exactor/ExactorSettings/sql/ExactorSettings_setup/upgrade-2012.06.14-2012.09.25.php +8 -4
- app/code/local/Exactor/Sales/Model/Observer.php +36 -11
- app/code/local/Exactor/Tax/Helper/Mapping.php +54 -11
- app/code/local/Exactor/Tax/etc/config.xml +1 -1
- lib/ExactorCommons/ExactorCommons.php +105 -1
- lib/ExactorCommons/config.php +12 -2
- package.xml +4 -4
app/code/local/Exactor/ExactorSettings/sql/ExactorSettings_setup/mysql4-install-14.04.2012.php
CHANGED
|
@@ -48,7 +48,6 @@
|
|
| 48 |
`AttributeName` varchar(50) DEFAULT NULL,
|
| 49 |
`CommitOption` varchar(2) DEFAULT NULL,
|
| 50 |
`EntityExemptions` varchar(2) DEFAULT NULL,
|
| 51 |
-
`EffectiveDate` date DEFAULT NULL,
|
| 52 |
PRIMARY KEY (`ID`)
|
| 53 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
| 54 |
|
| 48 |
`AttributeName` varchar(50) DEFAULT NULL,
|
| 49 |
`CommitOption` varchar(2) DEFAULT NULL,
|
| 50 |
`EntityExemptions` varchar(2) DEFAULT NULL,
|
|
|
|
| 51 |
PRIMARY KEY (`ID`)
|
| 52 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
| 53 |
|
app/code/local/Exactor/ExactorSettings/sql/ExactorSettings_setup/upgrade-2012.06.14-2012.09.25.php
CHANGED
|
@@ -24,14 +24,18 @@
|
|
| 24 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 25 |
*/
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
ALTER TABLE `exactor_account`
|
| 34 |
ADD COLUMN `EffectiveDate` date NULL;
|
| 35 |
");
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
$installer->endSetup();
|
| 24 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 25 |
*/
|
| 26 |
|
| 27 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
| 28 |
+
$installer = $this;
|
| 29 |
|
| 30 |
+
$installer->startSetup();
|
| 31 |
|
| 32 |
+
try {
|
| 33 |
+
$installer->run("
|
| 34 |
ALTER TABLE `exactor_account`
|
| 35 |
ADD COLUMN `EffectiveDate` date NULL;
|
| 36 |
");
|
| 37 |
+
} catch (Exception $e) {
|
| 38 |
+
Mage::log("Error during performing update script" . $e->getMessage());
|
| 39 |
+
}
|
| 40 |
|
| 41 |
$installer->endSetup();
|
app/code/local/Exactor/Sales/Model/Observer.php
CHANGED
|
@@ -21,6 +21,18 @@ class Exactor_Sales_Model_Observer {
|
|
| 21 |
/** @var IExactorLogger */
|
| 22 |
private $logger;
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
private function setupExactorCommonLibrary(){
|
| 25 |
$libDir = Mage::getBaseDir("lib") . '/ExactorCommons';
|
| 26 |
require_once($libDir . '/XmlProcessing.php');
|
|
@@ -88,7 +100,7 @@ class Exactor_Sales_Model_Observer {
|
|
| 88 |
$exactorProcessingService->partialPayment($invoiceRequest, new DateTime(), $this->getInvoiceIncrementId($invoice));
|
| 89 |
}
|
| 90 |
} catch (Exception $e) {
|
| 91 |
-
$this->logger->error("Can't commit transaction. See details above.", 'commitTransactionForInvoice');
|
| 92 |
}
|
| 93 |
}
|
| 94 |
|
|
@@ -136,7 +148,7 @@ class Exactor_Sales_Model_Observer {
|
|
| 136 |
* @param $order
|
| 137 |
* @return bool
|
| 138 |
*/
|
| 139 |
-
private function processFinishedOrder($order){
|
| 140 |
$merchantSettings = $this->loadMerchantSettings($order);
|
| 141 |
if ($merchantSettings==null) false;
|
| 142 |
$exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
|
|
@@ -153,20 +165,30 @@ class Exactor_Sales_Model_Observer {
|
|
| 153 |
$this->exactorProcessingService->getPluginCallback()->saveTransactionInfo($transactionInfo,$transactionInfo->getSignature());
|
| 154 |
// if CommitOption is set up to commit on sales order - do commit the
|
| 155 |
// latest transaction from the session storage
|
| 156 |
-
if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_SALES_ORDER)
|
|
|
|
| 157 |
$this->logger->info("Commiting transaction for order $orderId - " . $transactionInfo->getExactorTrnId(), 'processFinishedOrder');
|
| 158 |
try {
|
| 159 |
-
if (!$this->underEffectiveDate($merchantSettings->getEffectiveDate(), $order->getCreatedAt())){
|
| 160 |
-
$this->logger->info("Order " . $order->getIncrementId() ." is not under effective date. Skipping.",
|
| 161 |
-
"commitTransactionForOrder");
|
| 162 |
-
}
|
| 163 |
$invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoOrder($order, $merchantSettings);
|
| 164 |
$taxResponse = $this->commitTransactionForOrder($order, $merchantSettings);
|
| 165 |
-
}catch (Exception $e){
|
| 166 |
$this->logger->error("Can't commit transaction. See details above.", 'processFinishedOrder');
|
| 167 |
}
|
| 168 |
//$this->exactorProcessingService->commitExistingInvoiceForOrder($orderId);
|
| 169 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
return true;
|
| 171 |
}
|
| 172 |
|
|
@@ -197,7 +219,7 @@ class Exactor_Sales_Model_Observer {
|
|
| 197 |
} else {
|
| 198 |
$this->logger->error("New order should be represented by the single exactor transaction. Is", 'processFinishedOrder');
|
| 199 |
}
|
| 200 |
-
}catch (Exception $e){
|
| 201 |
$this->logger->error("Can't commit transaction. See details above.", 'processFinishedOrder');
|
| 202 |
}
|
| 203 |
return null;
|
|
@@ -322,9 +344,12 @@ class Exactor_Sales_Model_Observer {
|
|
| 322 |
$this->logger->trace('called', 'handleNewInvoice');
|
| 323 |
$merchantSettings = $this->loadMerchantSettings($observer->getInvoice()->getOrder());
|
| 324 |
if ($merchantSettings==null) return;
|
| 325 |
-
|
| 326 |
-
|
|
|
|
|
|
|
| 327 |
$this->commitTransactionForInvoice($observer->getInvoice(), $merchantSettings);
|
|
|
|
| 328 |
}
|
| 329 |
}
|
| 330 |
|
| 21 |
/** @var IExactorLogger */
|
| 22 |
private $logger;
|
| 23 |
|
| 24 |
+
/**
|
| 25 |
+
* TODO: REMOVE THIS COMMENTED CODE
|
| 26 |
+
* This object indicates whether invoice has been already handeled in compatibility mode or not.
|
| 27 |
+
* It is needed to prevent double handling of the same invoice for Magento versions which OnCreatedInvoice
|
| 28 |
+
* request in multi-shipping mode.
|
| 29 |
+
* Once invoice created, order increment id associated with this invoice will be pushed in this list.
|
| 30 |
+
* If list contains order ID this means that we already created commited transaction for it (at list
|
| 31 |
+
* in the current request cycle).
|
| 32 |
+
* @var bool
|
| 33 |
+
*/
|
| 34 |
+
private $invoiceProcessingCompatibilityList = array();
|
| 35 |
+
|
| 36 |
private function setupExactorCommonLibrary(){
|
| 37 |
$libDir = Mage::getBaseDir("lib") . '/ExactorCommons';
|
| 38 |
require_once($libDir . '/XmlProcessing.php');
|
| 100 |
$exactorProcessingService->partialPayment($invoiceRequest, new DateTime(), $this->getInvoiceIncrementId($invoice));
|
| 101 |
}
|
| 102 |
} catch (Exception $e) {
|
| 103 |
+
$this->logger->error("Can't commit transaction. See details above. :" . $e->getMessage() . $e->getTraceAsString(), 'commitTransactionForInvoice');
|
| 104 |
}
|
| 105 |
}
|
| 106 |
|
| 148 |
* @param $order
|
| 149 |
* @return bool
|
| 150 |
*/
|
| 151 |
+
private function processFinishedOrder(Mage_Sales_Model_Order $order){
|
| 152 |
$merchantSettings = $this->loadMerchantSettings($order);
|
| 153 |
if ($merchantSettings==null) false;
|
| 154 |
$exactorProcessingService = ExactorProcessingServiceFactory::getInstance()
|
| 165 |
$this->exactorProcessingService->getPluginCallback()->saveTransactionInfo($transactionInfo,$transactionInfo->getSignature());
|
| 166 |
// if CommitOption is set up to commit on sales order - do commit the
|
| 167 |
// latest transaction from the session storage
|
| 168 |
+
if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_SALES_ORDER)
|
| 169 |
+
{
|
| 170 |
$this->logger->info("Commiting transaction for order $orderId - " . $transactionInfo->getExactorTrnId(), 'processFinishedOrder');
|
| 171 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
$invoiceRequests = $this->exactorMappingHelper->buildInvoiceRequestForMagentoOrder($order, $merchantSettings);
|
| 173 |
$taxResponse = $this->commitTransactionForOrder($order, $merchantSettings);
|
| 174 |
+
} catch (Exception $e) {
|
| 175 |
$this->logger->error("Can't commit transaction. See details above.", 'processFinishedOrder');
|
| 176 |
}
|
| 177 |
//$this->exactorProcessingService->commitExistingInvoiceForOrder($orderId);
|
| 178 |
}
|
| 179 |
+
// TODO: REMOVE THIS COMMENTED CODE
|
| 180 |
+
/*else {
|
| 181 |
+
// Else we should check if there is invoice attached and we have commit option set in "On Invoice"
|
| 182 |
+
$incrementOrderId = $order->getIncrementId();
|
| 183 |
+
if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_INVOICE
|
| 184 |
+
&& count($order->getInvoiceCollection()) && !in_array($incrementOrderId, $this->invoiceProcessingCompatibilityList)) {
|
| 185 |
+
foreach ($order->getInvoiceCollection() as $invoice) {
|
| 186 |
+
$this->logger->info("Commiting transaction for order $orderId, Commit On Invoice. Compatibility logic", 'processFinishedOrder');
|
| 187 |
+
$this->commitTransactionForInvoice($invoice, $merchantSettings);
|
| 188 |
+
$this->invoiceProcessingCompatibilityList[] = $incrementOrderId;
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
}*/
|
| 192 |
return true;
|
| 193 |
}
|
| 194 |
|
| 219 |
} else {
|
| 220 |
$this->logger->error("New order should be represented by the single exactor transaction. Is", 'processFinishedOrder');
|
| 221 |
}
|
| 222 |
+
} catch (Exception $e) {
|
| 223 |
$this->logger->error("Can't commit transaction. See details above.", 'processFinishedOrder');
|
| 224 |
}
|
| 225 |
return null;
|
| 344 |
$this->logger->trace('called', 'handleNewInvoice');
|
| 345 |
$merchantSettings = $this->loadMerchantSettings($observer->getInvoice()->getOrder());
|
| 346 |
if ($merchantSettings==null) return;
|
| 347 |
+
// TODO: REMOVE THIS COMMENTED CODE
|
| 348 |
+
//$incrementOrderId = $observer->getInvoice()->getOrder()->getIncrementId();
|
| 349 |
+
if ($merchantSettings->getCommitOption() == Exactor_Core_Model_MerchantSettings::COMMIT_ON_INVOICE
|
| 350 |
+
/* && !in_array($incrementOrderId, $this->invoiceProcessingCompatibilityList)*/ ){ // If flag is set this means that invoice has been handled already in compatibility mode.
|
| 351 |
$this->commitTransactionForInvoice($observer->getInvoice(), $merchantSettings);
|
| 352 |
+
/*$this->invoiceProcessingCompatibilityList[]= $incrementOrderId;*/
|
| 353 |
}
|
| 354 |
}
|
| 355 |
|
app/code/local/Exactor/Tax/Helper/Mapping.php
CHANGED
|
@@ -153,7 +153,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 153 |
}
|
| 154 |
|
| 155 |
public function getShippingLineItemForQuoteAddress(Mage_Sales_Model_Quote_Address $quoteAddress,
|
| 156 |
-
Exactor_Core_Model_MerchantSettings $merchantSettings){
|
| 157 |
|
| 158 |
if ($quoteAddress->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) return null; // There is no shipping fees there
|
| 159 |
if ($quoteAddress->getShippingAmount()==0) return null;
|
|
@@ -277,11 +277,17 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 277 |
}else{
|
| 278 |
$lineItem->setSKU($this->getSKUForItem($magentoItem, $merchantSettings));
|
| 279 |
}
|
| 280 |
-
|
|
|
|
|
|
|
| 281 |
// Check if it is bundle or groped product
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
$lineItem->setDescription($lineItem->getDescription() . " :: Dynamic Price");
|
| 286 |
return null; // Doesn't show it in the Exactor transaction.
|
| 287 |
}
|
|
@@ -289,8 +295,33 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 289 |
return $lineItem;
|
| 290 |
}
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
$discountedLine = self::MSG_DISCOUNTED_BY . $discountAmount;
|
| 295 |
$item->setDescription($item->getDescription() . " ($discountedLine)");
|
| 296 |
$item->setGrossAmount($item->getGrossAmount() - $discountAmount);
|
|
@@ -384,7 +415,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 384 |
if ($isEstimation){
|
| 385 |
// It is possible that postal code or state will be missing on the tax estimation form
|
| 386 |
// In this case we will try to determine region basing on the given Postal Code
|
| 387 |
-
if (strlen(trim($shipToAddress->getStateOrProvince()))==
|
| 388 |
$shipToAddress->setStateOrProvince(RegionResolver::getInstance()->getStateOrProvinceByCode(trim($shipToAddress->getPostalCode())));
|
| 389 |
}
|
| 390 |
$billingAddress = $shipToAddress;
|
|
@@ -476,7 +507,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 476 |
$invoiceRequest->setShipFrom($merchantSettings->getExactorShippingAddress());
|
| 477 |
$invoiceRequest->setCurrencyCode($creditMemo->getOrder()->getOrderCurrencyCode());
|
| 478 |
$invoiceRequest->setPurchaseOrderNumber($creditMemo->getOrder()->getIncrementId());
|
| 479 |
-
$invoiceRequest->setSaleDate(
|
| 480 |
$invoiceRequest->setExemptionId($this->getExemptionIdForCreditMemo($creditMemo, $merchantSettings));
|
| 481 |
// Line items
|
| 482 |
$magentoItems = $creditMemo->getAllItems();
|
|
@@ -539,6 +570,17 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 539 |
return $result;
|
| 540 |
}
|
| 541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
public function buildInvoiceRequestForMagentoInvoice(Mage_Sales_Model_Order_Invoice $invoice, Exactor_Core_Model_MerchantSettings $merchantSettings){
|
| 543 |
$result = array();
|
| 544 |
$invoiceRequest = new InvoiceRequestType();
|
|
@@ -547,7 +589,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 547 |
$invoiceRequest->setShipFrom($merchantSettings->getExactorShippingAddress());
|
| 548 |
$invoiceRequest->setCurrencyCode($invoice->getOrder()->getOrderCurrencyCode());
|
| 549 |
$invoiceRequest->setPurchaseOrderNumber($invoice->getOrder()->getIncrementId());
|
| 550 |
-
$invoiceRequest->setSaleDate(
|
| 551 |
$invoiceRequest->setExemptionId($this->getExemptionIdForOrder($invoice->getOrder(), $merchantSettings));
|
| 552 |
//$invoiceRequest->setExemptionId($this->getExemptionIdForCreditMemo($creditMemo, $merchantSettings));
|
| 553 |
// Line items
|
|
@@ -588,7 +630,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 588 |
$invoiceRequest->setShipFrom($merchantSettings->getExactorShippingAddress());
|
| 589 |
$invoiceRequest->setCurrencyCode($order->getOrderCurrencyCode());
|
| 590 |
$invoiceRequest->setPurchaseOrderNumber($order->getIncrementId());
|
| 591 |
-
$invoiceRequest->setSaleDate(
|
| 592 |
$invoiceRequest->setExemptionId($this->getExemptionIdForOrder($order, $merchantSettings));
|
| 593 |
// Line items
|
| 594 |
$magentoItems = $order->getAllItems();
|
|
@@ -596,6 +638,7 @@ class Exactor_Tax_Helper_Mapping extends Mage_Core_Helper_Abstract {
|
|
| 596 |
$exactorLineItem = $this->buildLineItemForMagentoItem($magentoItem, new Mage_Sales_Model_Quote_Address(), $merchantSettings);
|
| 597 |
if ($exactorLineItem != null){
|
| 598 |
$exactorLineItem->setQuantity($magentoItem->getQtyOrdered());
|
|
|
|
| 599 |
}
|
| 600 |
$invoiceRequest->addLineItem($exactorLineItem);
|
| 601 |
}
|
| 153 |
}
|
| 154 |
|
| 155 |
public function getShippingLineItemForQuoteAddress(Mage_Sales_Model_Quote_Address $quoteAddress,
|
| 156 |
+
Exactor_Core_Model_MerchantSettings $merchantSettings) {
|
| 157 |
|
| 158 |
if ($quoteAddress->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) return null; // There is no shipping fees there
|
| 159 |
if ($quoteAddress->getShippingAmount()==0) return null;
|
| 277 |
}else{
|
| 278 |
$lineItem->setSKU($this->getSKUForItem($magentoItem, $merchantSettings));
|
| 279 |
}
|
| 280 |
+
if (!$this->isDiscountExempt($magentoItem)) {
|
| 281 |
+
$this->applyDiscountToLineItem($lineItem, $magentoItem->getDiscountAmount());
|
| 282 |
+
}
|
| 283 |
// Check if it is bundle or groped product
|
| 284 |
+
$product = $magentoItem->getProduct();
|
| 285 |
+
if ($product==null) {
|
| 286 |
+
$product = $magentoItem->getOrderItem()->getProduct();
|
| 287 |
+
}
|
| 288 |
+
if (in_array($product->getTypeId(), array(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE))) {
|
| 289 |
+
if ($product->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
|
| 290 |
+
$lineItem->setGrossAmount(0);
|
| 291 |
$lineItem->setDescription($lineItem->getDescription() . " :: Dynamic Price");
|
| 292 |
return null; // Doesn't show it in the Exactor transaction.
|
| 293 |
}
|
| 295 |
return $lineItem;
|
| 296 |
}
|
| 297 |
|
| 298 |
+
/**
|
| 299 |
+
* @param \Mage_Sales_Model_Quote_Address_Item|\Mage_Sales_Model_Quote_Item $magentoItem
|
| 300 |
+
* @return void
|
| 301 |
+
*/
|
| 302 |
+
private function isDiscountExempt($magentoItem){
|
| 303 |
+
try {
|
| 304 |
+
$config = ExactorPluginConfig::getInstance();
|
| 305 |
+
if (!$config->getFeatureConfig()->isFeatureEnabled(EXACTOR_CONFIG_FEATURE_EXEMPT_DISCOUNTS)) return false;
|
| 306 |
+
$exempted = $config->get(EXACTOR_CONFIG_FEATURE_EXEMPT_DISCOUNTS);
|
| 307 |
+
if ($magentoItem->getOrderItem() != null){
|
| 308 |
+
$magentoItem = $magentoItem->getOrderItem();
|
| 309 |
+
}
|
| 310 |
+
$actual = preg_split('/,/', $magentoItem->getAppliedRuleIds());
|
| 311 |
+
foreach ($actual as $actualId) {
|
| 312 |
+
if (in_array((int)$actualId, $exempted)) {
|
| 313 |
+
return true;
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
} catch (Exception $e) {
|
| 317 |
+
// Nothing to do. just log
|
| 318 |
+
$this->logger->error("Error while determining if discount is exempt:", $e->getMessage(), 'isDiscountExempt');
|
| 319 |
+
}
|
| 320 |
+
return false;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
private function applyDiscountToLineItem(LineItemType &$item, $discountAmount=0){
|
| 324 |
+
if ($discountAmount > 0){
|
| 325 |
$discountedLine = self::MSG_DISCOUNTED_BY . $discountAmount;
|
| 326 |
$item->setDescription($item->getDescription() . " ($discountedLine)");
|
| 327 |
$item->setGrossAmount($item->getGrossAmount() - $discountAmount);
|
| 415 |
if ($isEstimation){
|
| 416 |
// It is possible that postal code or state will be missing on the tax estimation form
|
| 417 |
// In this case we will try to determine region basing on the given Postal Code
|
| 418 |
+
if (strlen(trim($shipToAddress->getStateOrProvince()))==0 && strlen(trim($shipToAddress->getPostalCode()))!=0){
|
| 419 |
$shipToAddress->setStateOrProvince(RegionResolver::getInstance()->getStateOrProvinceByCode(trim($shipToAddress->getPostalCode())));
|
| 420 |
}
|
| 421 |
$billingAddress = $shipToAddress;
|
| 507 |
$invoiceRequest->setShipFrom($merchantSettings->getExactorShippingAddress());
|
| 508 |
$invoiceRequest->setCurrencyCode($creditMemo->getOrder()->getOrderCurrencyCode());
|
| 509 |
$invoiceRequest->setPurchaseOrderNumber($creditMemo->getOrder()->getIncrementId());
|
| 510 |
+
$invoiceRequest->setSaleDate($this->getCreatedAtDateForMageOrder($creditMemo->getOrder()));
|
| 511 |
$invoiceRequest->setExemptionId($this->getExemptionIdForCreditMemo($creditMemo, $merchantSettings));
|
| 512 |
// Line items
|
| 513 |
$magentoItems = $creditMemo->getAllItems();
|
| 570 |
return $result;
|
| 571 |
}
|
| 572 |
|
| 573 |
+
private function getCreatedAtDateForMageOrder(Mage_Sales_Model_Order $order, $default='now') {
|
| 574 |
+
$res = $default;
|
| 575 |
+
try{
|
| 576 |
+
$res= '@'.$order->getCreatedAtDate()->getTimestamp();
|
| 577 |
+
} catch (Exception $e) {
|
| 578 |
+
$this->logger->error("Can't get date. Using default value." . $e->getMessage(),
|
| 579 |
+
'getCreatedAtDateForMageInvoice');
|
| 580 |
+
}
|
| 581 |
+
return new DateTime($res);
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
public function buildInvoiceRequestForMagentoInvoice(Mage_Sales_Model_Order_Invoice $invoice, Exactor_Core_Model_MerchantSettings $merchantSettings){
|
| 585 |
$result = array();
|
| 586 |
$invoiceRequest = new InvoiceRequestType();
|
| 589 |
$invoiceRequest->setShipFrom($merchantSettings->getExactorShippingAddress());
|
| 590 |
$invoiceRequest->setCurrencyCode($invoice->getOrder()->getOrderCurrencyCode());
|
| 591 |
$invoiceRequest->setPurchaseOrderNumber($invoice->getOrder()->getIncrementId());
|
| 592 |
+
$invoiceRequest->setSaleDate($this->getCreatedAtDateForMageOrder($invoice->getOrder()));
|
| 593 |
$invoiceRequest->setExemptionId($this->getExemptionIdForOrder($invoice->getOrder(), $merchantSettings));
|
| 594 |
//$invoiceRequest->setExemptionId($this->getExemptionIdForCreditMemo($creditMemo, $merchantSettings));
|
| 595 |
// Line items
|
| 630 |
$invoiceRequest->setShipFrom($merchantSettings->getExactorShippingAddress());
|
| 631 |
$invoiceRequest->setCurrencyCode($order->getOrderCurrencyCode());
|
| 632 |
$invoiceRequest->setPurchaseOrderNumber($order->getIncrementId());
|
| 633 |
+
$invoiceRequest->setSaleDate($this->getCreatedAtDateForMageOrder($order));
|
| 634 |
$invoiceRequest->setExemptionId($this->getExemptionIdForOrder($order, $merchantSettings));
|
| 635 |
// Line items
|
| 636 |
$magentoItems = $order->getAllItems();
|
| 638 |
$exactorLineItem = $this->buildLineItemForMagentoItem($magentoItem, new Mage_Sales_Model_Quote_Address(), $merchantSettings);
|
| 639 |
if ($exactorLineItem != null){
|
| 640 |
$exactorLineItem->setQuantity($magentoItem->getQtyOrdered());
|
| 641 |
+
$exactorLineItem->setId(self::INDEXED_LINE_ITEM_ID_PREFIX . $magentoItem->getId());
|
| 642 |
}
|
| 643 |
$invoiceRequest->addLineItem($exactorLineItem);
|
| 644 |
}
|
app/code/local/Exactor/Tax/etc/config.xml
CHANGED
|
@@ -28,7 +28,7 @@
|
|
| 28 |
<config>
|
| 29 |
<modules>
|
| 30 |
<Exactor_Tax>
|
| 31 |
-
<version>2012.
|
| 32 |
</Exactor_Tax>
|
| 33 |
</modules>
|
| 34 |
<global>
|
| 28 |
<config>
|
| 29 |
<modules>
|
| 30 |
<Exactor_Tax>
|
| 31 |
+
<version>2012.11.02</version>
|
| 32 |
</Exactor_Tax>
|
| 33 |
</modules>
|
| 34 |
<global>
|
lib/ExactorCommons/ExactorCommons.php
CHANGED
|
@@ -145,13 +145,117 @@ class ExactorLoggingFactory{
|
|
| 145 |
{
|
| 146 |
return $this->logLevel;
|
| 147 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
}
|
| 151 |
|
| 152 |
/* ******************** EXACTOR CONNECTOR ***************************/
|
| 153 |
|
| 154 |
-
class ExactorConnector{
|
| 155 |
|
| 156 |
private $endpointUrl='';
|
| 157 |
|
| 145 |
{
|
| 146 |
return $this->logLevel;
|
| 147 |
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/* ******************************************************************/
|
| 151 |
+
|
| 152 |
+
class ConfigHolder {
|
| 153 |
+
protected $_config;
|
| 154 |
+
public function __construct() {
|
| 155 |
+
$this->_config = array();
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
public function get($property, $default=null){
|
| 159 |
+
if (array_key_exists($property, $this->_config)){
|
| 160 |
+
return $this->_config[$property];
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
public function __sleep()
|
| 165 |
+
{
|
| 166 |
+
return array('_config');
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
public function set($property, $value){
|
| 170 |
+
$this->_config[$property]=$value;
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
class FeatureConfigHolder extends ConfigHolder {
|
| 175 |
+
public function __construct(){
|
| 176 |
+
parent::__construct();
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
public function enableFeature($featureName) {
|
| 180 |
+
$this->set('enable-' . $featureName, "true");
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
public function disableFeature($featureName) {
|
| 184 |
+
$this->set('enable-' . $featureName, "false");
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
public function isFeatureEnabled($featureName) {
|
| 188 |
+
return $this->get('enable-' . $featureName) == "true";
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
class FeatureConfigManager {
|
| 194 |
+
private $encriptionKey='';
|
| 195 |
|
| 196 |
+
/**
|
| 197 |
+
* Decodes config string and returns an object.
|
| 198 |
+
*
|
| 199 |
+
* @param $configString
|
| 200 |
+
* @return FeatureConfigHolder
|
| 201 |
+
*/
|
| 202 |
+
public function readConfigFromString($configString) {
|
| 203 |
+
$obj = unserialize(base64_decode(preg_replace("/[\\s\\n]+/","",$configString)));
|
| 204 |
+
if ($obj == false)
|
| 205 |
+
return new FeatureConfigHolder();
|
| 206 |
+
else
|
| 207 |
+
return $obj;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/**
|
| 211 |
+
* Returns config encoded as string
|
| 212 |
+
*
|
| 213 |
+
* @param FeatureConfigHolder $config
|
| 214 |
+
* @return string
|
| 215 |
+
*/
|
| 216 |
+
public function encodeConfig(FeatureConfigHolder $config){
|
| 217 |
+
$serialized = serialize($config);
|
| 218 |
+
return base64_encode($serialized);
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
class ExactorPluginConfig extends ConfigHolder {
|
| 223 |
+
private static $_instance;
|
| 224 |
+
private $featureConfig;
|
| 225 |
+
|
| 226 |
+
/**
|
| 227 |
+
* @static
|
| 228 |
+
* @return ExactorMagentoConfig
|
| 229 |
+
*/
|
| 230 |
+
public static function getInstance(){
|
| 231 |
+
if (!isset(self::$_instance)) {
|
| 232 |
+
$className = __CLASS__;
|
| 233 |
+
self::$_instance = new $className;
|
| 234 |
+
}
|
| 235 |
+
return self::$_instance;
|
| 236 |
+
}
|
| 237 |
|
| 238 |
+
public function __construct() {
|
| 239 |
+
$this->config = array();
|
| 240 |
+
$this->featureConfig = new FeatureConfigHolder();
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
public function getFeatureConfig() {
|
| 244 |
+
return $this->featureConfig;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
public function pushFeatureConfigString($configString) {
|
| 248 |
+
$configManager = new FeatureConfigManager();
|
| 249 |
+
$config = $configManager->readConfigFromString($configString);
|
| 250 |
+
if ($config) {
|
| 251 |
+
$this->featureConfig = $config;
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
}
|
| 255 |
|
| 256 |
/* ******************** EXACTOR CONNECTOR ***************************/
|
| 257 |
|
| 258 |
+
class ExactorConnector {
|
| 259 |
|
| 260 |
private $endpointUrl='';
|
| 261 |
|
lib/ExactorCommons/config.php
CHANGED
|
@@ -4,8 +4,18 @@
|
|
| 4 |
* Date: 4/20/12
|
| 5 |
* Time: 10:36 AM
|
| 6 |
*/
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
ExactorProcessingServiceFactory::getInstance()->setup(new MagentoExactorCallback());
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
* Date: 4/20/12
|
| 5 |
* Time: 10:36 AM
|
| 6 |
*/
|
| 7 |
+
/* Available config options */
|
| 8 |
+
define('EXACTOR_CONFIG_EXEMPT_DISCOUNTS', 'exempt-descounts');
|
| 9 |
+
define('EXACTOR_CONFIG_FEATURE_EXEMPT_DISCOUNTS', 'discount-exemptions');
|
| 10 |
|
| 11 |
+
/* Initializing factories */
|
| 12 |
+
ExactorLoggingFactory::getInstance()->setup('MagentoLogger', IExactorLogger::TRACE);
|
| 13 |
+
ExactorConnectionFactory::getInstance()->setup('Magento','v20121112');
|
| 14 |
ExactorProcessingServiceFactory::getInstance()->setup(new MagentoExactorCallback());
|
| 15 |
|
| 16 |
+
/* Initializing configuration object */
|
| 17 |
+
$config = ExactorPluginConfig::getInstance();
|
| 18 |
+
$config->pushFeatureConfigString("TzoxOToiRmVhdHVyZUNvbmZpZ0hvbGRlciI6MTp7czoxMDoiACoAX2NvbmZpZyI7YToxOntzOjI2OiJlbmFibGUtZGlzY291bnQtZXhlbXB0aW9ucyI7czo0OiJ0cnVlIjt9fQ==");
|
| 19 |
+
|
| 20 |
+
/* Pushing parameters */
|
| 21 |
+
$config->set(EXACTOR_CONFIG_FEATURE_EXEMPT_DISCOUNTS, array(1, 2, 3));
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Mage_Exactor_Tax</name>
|
| 4 |
-
<version>2012.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
<channel>community</channel>
|
|
@@ -12,9 +12,9 @@ Once installed, neither the merchant, nor the customer, need to perform any addi
|
|
| 12 |
For additional information, please refer to the Exactor Magento User Guide that is attached to the plug-in, or which you can download directly from the Exactor control panel (navigate to Account Management Integration Points & PlugIns).</description>
|
| 13 |
<notes>Supported Magento 1.5.0.0 - 1.7.x, Magento Enterprise 1.8-1.12.x</notes>
|
| 14 |
<authors><author><name>Exactor, Inc.</name><user>exactor</user><email>support@exactor.com</email></author></authors>
|
| 15 |
-
<date>2012-
|
| 16 |
-
<time>
|
| 17 |
-
<contents><target name="magelocal"><dir name="Exactor"><dir name="Core"><dir name="Helper"><file name="SessionCache.php" hash="72692a33574f8ba2f1858e2e93aa4edf"/></dir><dir name="Model"><file name="ExactorTransaction.php" hash="852aa20f6e3b7aa0001439d4bffe9724"/><file name="MerchantSettings.php" hash="71a7c2308f6f0eda102ae84dd90df751"/><dir name="Mysql4"><dir name="ExactorTransaction"><file name="Collection.php" hash="c7b890b4d3ab35e65a3856ae0e2fdf72"/></dir><file name="ExactorTransaction.php" hash="c91aebaae767613acf1c439a8b513c3b"/><dir name="MerchantSettings"><file name="Collection.php" hash="c1593f52e582e601409c4651c37495af"/><file name="Collection.php~" hash="d360e202eb30432ac41dc023ce13ffc0"/></dir><file name="MerchantSettings.php" hash="8f22b76bb64cdc7b1deb6f0e38889905"/></dir><dir name="Type"><file name="Onepage.php" hash="2441fb08bbeb579831cea4d3fbd31104"/></dir></dir><dir name="etc"><file name="config.xml" hash="98ecc82a5f7b74ac0bfc0f7ab512afdb"/></dir></dir><dir name="ExactorSettings"><dir name="Block"><file name="Form.php" hash="5ea1d72197306072fe5fad9b97d109e8"/></dir><dir name="Helper"><file name="Data.php" hash="a23bb9c251f0dbb77c107d01dde39e86"/><file name="VersionResolver.php" hash="14dce068dfe2a7d3364c4bd29e6f8431"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FormController.php" hash="c0985258b110e0314e6b6ea091ae8c19"/></dir><file name="AjaxController.php" hash="c07aeeca00e1408e52945fc027569793"/><file name="IndexController.php" hash="f47cbc274dd68c57c30b60bbee69259e"/></dir><dir name="etc"><file name="config.xml" hash="674c326bfc901d0becf7c94ddcdd1452"/></dir><dir name="sql"><dir name="ExactorSettings_setup"><file name="mysql4-install-14.04.2012.php" hash="
|
| 18 |
<compatible/>
|
| 19 |
<dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
|
| 20 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Mage_Exactor_Tax</name>
|
| 4 |
+
<version>2012.11.12</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
<channel>community</channel>
|
| 12 |
For additional information, please refer to the Exactor Magento User Guide that is attached to the plug-in, or which you can download directly from the Exactor control panel (navigate to Account Management Integration Points & PlugIns).</description>
|
| 13 |
<notes>Supported Magento 1.5.0.0 - 1.7.x, Magento Enterprise 1.8-1.12.x</notes>
|
| 14 |
<authors><author><name>Exactor, Inc.</name><user>exactor</user><email>support@exactor.com</email></author></authors>
|
| 15 |
+
<date>2012-11-12</date>
|
| 16 |
+
<time>17:40:52</time>
|
| 17 |
+
<contents><target name="magelocal"><dir name="Exactor"><dir name="Core"><dir name="Helper"><file name="SessionCache.php" hash="72692a33574f8ba2f1858e2e93aa4edf"/></dir><dir name="Model"><file name="ExactorTransaction.php" hash="852aa20f6e3b7aa0001439d4bffe9724"/><file name="MerchantSettings.php" hash="71a7c2308f6f0eda102ae84dd90df751"/><dir name="Mysql4"><dir name="ExactorTransaction"><file name="Collection.php" hash="c7b890b4d3ab35e65a3856ae0e2fdf72"/></dir><file name="ExactorTransaction.php" hash="c91aebaae767613acf1c439a8b513c3b"/><dir name="MerchantSettings"><file name="Collection.php" hash="c1593f52e582e601409c4651c37495af"/><file name="Collection.php~" hash="d360e202eb30432ac41dc023ce13ffc0"/></dir><file name="MerchantSettings.php" hash="8f22b76bb64cdc7b1deb6f0e38889905"/></dir><dir name="Type"><file name="Onepage.php" hash="2441fb08bbeb579831cea4d3fbd31104"/></dir></dir><dir name="etc"><file name="config.xml" hash="98ecc82a5f7b74ac0bfc0f7ab512afdb"/></dir></dir><dir name="ExactorSettings"><dir name="Block"><file name="Form.php" hash="5ea1d72197306072fe5fad9b97d109e8"/></dir><dir name="Helper"><file name="Data.php" hash="a23bb9c251f0dbb77c107d01dde39e86"/><file name="VersionResolver.php" hash="14dce068dfe2a7d3364c4bd29e6f8431"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FormController.php" hash="c0985258b110e0314e6b6ea091ae8c19"/></dir><file name="AjaxController.php" hash="c07aeeca00e1408e52945fc027569793"/><file name="IndexController.php" hash="f47cbc274dd68c57c30b60bbee69259e"/></dir><dir name="etc"><file name="config.xml" hash="674c326bfc901d0becf7c94ddcdd1452"/></dir><dir name="sql"><dir name="ExactorSettings_setup"><file name="mysql4-install-14.04.2012.php" hash="f35af1e12921b57479cb4b5677937a0c"/><file name="upgrade-2012.06.14-2012.09.25.php" hash="174fda5224bc23cdf147fb059d079478"/></dir></dir></dir><dir name="Sales"><dir name="Model"><file name="Observer.php" hash="f3a499093151b8a29123b7e005bdabea"/></dir><dir name="etc"><file name="config.xml" hash="ba31618f5165dda20010c40e7ef8dad1"/></dir></dir><dir name="Tax"><dir name="Helper"><file name="Calculation.php" hash="29c5252bdd48b173c90588f449114024"/><file name="Mapping.php" hash="89d9e6c612bd51629e63e0537a34bf2c"/></dir><dir name="Model"><dir name="Sales"><dir name="Total"><dir name="Quote"><dir name="Nominal"><file name="Tax.php" hash="156eff380df5b16db55449759f193490"/></dir><file name="Tax.php" hash="2177508f9375ba7c250ae165a798de72"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="6fe61bee324add44f51c36cb5027c29b"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="exactorsettings.xml" hash="3707eac08d2393c8796eebf1cf7a0bd9"/><file name="exactoronestepcheckout.xml" hash="9fdfa1db5e4e60b4eec8f348c10aab07"/></dir><dir name="template"><dir name="ExactorSettings"><file name="settingsform.phtml" hash="3f6e14533076ab97dbb0c98ba770bf87"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="exactoronestepcheckout.xml" hash="9fdfa1db5e4e60b4eec8f348c10aab07"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Exactor.xml" hash="e8997e8e36a265141b37790caaef39d6"/></dir></target><target name="mageweb"><dir name="js"><dir name="exactor"><file name="exactor.js" hash="5c23e40f4034e50a6e0df5b1c708b7e1"/></dir></dir></target><target name="magelib"><dir name="ExactorCommons"><file name="ExactorCommons.php" hash="b25d68bc8e7b2dc5f427a4681ff4472c"/><file name="ExactorDomainObjects.php" hash="ae42cff2f17d21922685e46dd47d93ac"/><file name="Magento.php" hash="76da7333fe0692053a47f8564c7b513a"/><file name="RegionResolver.php" hash="2537638a7895a169cee4b1df786d22fb"/><file name="XmlProcessing.php" hash="383fd21839889d720e2094e83ccc7a2a"/><file name="config.php" hash="f404f3dd010f4247455442f168f9e18b"/></dir></target></contents>
|
| 18 |
<compatible/>
|
| 19 |
<dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
|
| 20 |
</package>
|
