-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,030 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
logs | ||
.idea | ||
releases | ||
releases | ||
/*.sh | ||
/scoper.inc.php | ||
/UpdateVersionNumber.php | ||
/composer.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
namespace MollieShopware\Command; | ||
|
||
use Mollie\Api\MollieApiClient; | ||
use MollieShopware\Components\Config; | ||
use MollieShopware\Models\Transaction; | ||
use MollieShopware\Models\TransactionRepository; | ||
use Shopware\Commands\ShopwareCommand; | ||
use Shopware\Components\Model\ModelManager; | ||
use Shopware\Models\Order\Order; | ||
use Shopware\Models\Order\Repository; | ||
use Shopware\Models\Order\Status; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class KlarnaShippingCommand extends ShopwareCommand | ||
{ | ||
/** @var Config */ | ||
private $config; | ||
|
||
/** @var ModelManager */ | ||
private $modelManager; | ||
|
||
/** @var MollieApiClient */ | ||
private $apiClient; | ||
|
||
public function __construct( | ||
Config $config, | ||
ModelManager $modelManager, | ||
MollieApiClient $apiClient, | ||
$name = null | ||
) | ||
{ | ||
parent::__construct($name); | ||
|
||
$this->config = $config; | ||
$this->modelManager = $modelManager; | ||
$this->apiClient = $apiClient; | ||
} | ||
|
||
public function configure() | ||
{ | ||
$this | ||
->setName('mollie:ship:klarna') | ||
->setDescription('Ship completed Klarna orders'); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
/** @var Transaction[] $transactions */ | ||
$transactions = null; | ||
|
||
/** @var TransactionRepository $transactionRepository */ | ||
$transactionRepository = $this->modelManager | ||
->getRepository(Transaction::class); | ||
|
||
if ($transactionRepository !== null) { | ||
$transactions = $transactionRepository->findBy([ | ||
'isShipped' => false, | ||
'paymentMethod' => 'mollie_klarna' | ||
]); | ||
} | ||
|
||
if ( | ||
$transactions !== null | ||
&& is_array($transactions) | ||
) { | ||
$output->writeln(count($transactions) . ' orders to update.'); | ||
|
||
foreach ($transactions as $transaction) { | ||
$output->writeln('Updating order ' . $transaction->getOrderNumber()); | ||
|
||
/** @var Order $order */ | ||
$order = null; | ||
|
||
if ($transaction->getOrderId() === null) { | ||
continue; | ||
} | ||
|
||
/** @var Repository $orderRepository */ | ||
$orderRepository = $this->modelManager->getRepository(Order::class); | ||
|
||
if ($orderRepository === null) { | ||
continue; | ||
} | ||
|
||
/** @var Order $order */ | ||
$order = $orderRepository->find($transaction->getOrderId()); | ||
|
||
if ($order === null) { | ||
continue; | ||
} | ||
|
||
// Ship order | ||
try { | ||
$mollieOrder = $this->apiClient->orders->get($transaction->getMollieId()); | ||
|
||
if ( | ||
$mollieOrder !== null | ||
&& $order->getOrderStatus()->getId() === $this->config->getKlarnaShipOnStatus() | ||
&& !in_array($order->getPaymentStatus()->getId(), [ | ||
Status::PAYMENT_STATE_OPEN, | ||
Status::PAYMENT_STATE_THE_PROCESS_HAS_BEEN_CANCELLED | ||
], true) | ||
) { | ||
$mollieOrder->shipAll(); | ||
$transaction->setIsShipped(true); | ||
} | ||
} catch (\Exception $e) { | ||
// | ||
} | ||
|
||
// Save order | ||
try { | ||
$transactionRepository->save($transaction); | ||
} catch (\Exception $e) { | ||
// | ||
} | ||
} | ||
|
||
$output->writeln('Done.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace MollieShopware\Components\Helpers; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Shopware\Components\Logger; | ||
|
||
class LogHelper | ||
{ | ||
const LOG_CRITICAL = 'critical'; | ||
const LOG_DEBUG = 'debug'; | ||
const LOG_ERROR = 'error'; | ||
const LOG_INFO = 'info'; | ||
const LOG_WARNING = 'warning'; | ||
|
||
/** @var ContainerInterface */ | ||
private static $container; | ||
|
||
/** @var Logger */ | ||
private static $pluginLogger; | ||
|
||
/** | ||
* Creates a new instance of the log helper. | ||
* | ||
* @param ContainerInterface $container | ||
*/ | ||
public function __construct( | ||
ContainerInterface $container | ||
) | ||
{ | ||
static::$container = $container; | ||
} | ||
|
||
/** | ||
* Logs a message to the plugin logger. | ||
* | ||
* @param string $message | ||
* @param string $logMethod | ||
* @param null $exception | ||
* @return bool | ||
*/ | ||
public static function logMessage($message, $logMethod = self::LOG_ERROR, $exception = null) | ||
{ | ||
// Check if the log method exists | ||
if (!method_exists(static::pluginLogger(), $logMethod)) { | ||
$logMethod = self::LOG_DEBUG; | ||
|
||
// Throw a warning that the log level is unknown | ||
trigger_error( | ||
'Using an unknown log level, fallback to debug', | ||
E_USER_WARNING | ||
); | ||
} | ||
|
||
return static::pluginLogger()->$logMethod($message, [$exception]); | ||
} | ||
|
||
/** | ||
* Returns the plugin logger. | ||
* | ||
* @param ContainerInterface|null $container | ||
* @return Logger | ||
*/ | ||
private static function pluginLogger(ContainerInterface $container = null) | ||
{ | ||
// Set the container | ||
static::$container = ($container === null ? static::$container : $container); | ||
|
||
// Get the plugin logger from the container | ||
if (static::$pluginLogger === null && static::$container !== null) { | ||
static::$pluginLogger = static::$container->get('pluginlogger'); | ||
} | ||
|
||
return static::$pluginLogger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.