Skip to content

Commit

Permalink
Merge branch 'MAG-366-433' into 4.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ébano Penha Andrello Lopes committed Apr 19, 2019
2 parents 5d9e564 + 3dba6c3 commit 685e312
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class Signifyd_Connect_Model_Container_Fingerprint extends Enterprise_PageCache_Model_Container_Abstract
{
/**
* Get identifier from cookies
*
* @return string
*/
protected function _getCacheId()
{
return $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CART, '')
. $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '');
}

/**
* Render block content
*
* @return string
*/
protected function _renderBlock()
{
return $this->_getPlaceHolderBlock()->toHtml();
}
}
57 changes: 56 additions & 1 deletion www/magento/app/code/community/Signifyd/Connect/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,29 +326,84 @@ public function authorizeOrder(Mage_Sales_Model_Order $order)
*/
public function generateInvoice(Mage_Sales_Model_Order $order)
{
$incrementId = $order->getIncrementId();

if (!$order->canInvoice()) {
$this->logger->addLog("Order {$order->getIncrementId()} cannot be invoiced");
$state = $order->getState();

$notInvoiceableStates = array(
$order::STATE_CANCELED,
$order::STATE_PAYMENT_REVIEW,
$order::STATE_COMPLETE,
$order::STATE_CLOSED,
$order::STATE_HOLDED
);

if (in_array($state, $notInvoiceableStates)) {
$reason = "order is on {$state} state";
} elseif ($order->getActionFlag($order::ACTION_FLAG_UNHOLD) === false) {
$reason = "order action flag is set to do not invoice";
} else {
$canInvoiceAny = false;

/** @var Mage_Sales_Model_Order_Item $item */
foreach ($order->getAllItems() as $item) {
if ($item->getQtyToInvoice() > 0 && !$item->getLockedDoInvoice()) {
$canInvoiceAny = true;
break;
}
}

if ($canInvoiceAny) {
$reason = "unknown reason";
} else {
$reason = "no items can be invoiced";
}
}

$order->addStatusHistoryComment("Signifyd: unable to create invoice, {$reason}");
$order->save();

$this->logger->addLog("Order {$incrementId}, unable to create invoice, {$reason}");

return false;
}

try {
/** @var Mage_Sales_Model_Order_Invoice $invoice */
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();

if ($invoice->isEmpty()) {
throw new Exception('failed to generate invoice');
}

if ($invoice->getTotalQty() == 0) {
throw new Exception('no items found to invoice');
}

$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();

$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();

$this->logger->addLog("Invoice was created for order: {$order->getIncrementId()}");

$invoice->addComment('Signifyd: create order invoice', false);
$invoice->sendEmail();
$invoice->setEmailSent(true);
$invoice->save();

$order->addStatusHistoryComment("Signifyd: create order invoice: {$invoice->getIncrementId()}");
$order->save();
} catch (Exception $e) {
$this->logger->addLog('Exception while creating invoice: ' . $e->__toString());

$order->addStatusHistoryComment("Signifyd: unable to create invoice, {$e->getMessage()}");
$order->save();

return false;
}

Expand Down
11 changes: 11 additions & 0 deletions www/magento/app/code/community/Signifyd/Connect/etc/cache.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<config>
<placeholders>
<signifyd_connect_fingerprint>
<block>signifyd_connect/device</block>
<placeholder>SIGNIFYD_CONNECT_FINGERPRINT</placeholder>
<container>Signifyd_Connect_Model_Container_Fingerprint</container>
<cache_lifetime>86400</cache_lifetime>
</signifyd_connect_fingerprint>
</placeholders>
</config>

0 comments on commit 685e312

Please sign in to comment.