Skip to content
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
2 changes: 2 additions & 0 deletions Api/OrderImportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface OrderImportInterface
* @param string $modified
* @param string $sign
* @param mixed $payment
* @param mixed $customerIdCard
* @param mixed $itemsToFulfill
* @param mixed $items
* @param mixed $deliveryAddress
Expand Down Expand Up @@ -61,6 +62,7 @@ public function import(
$modified,
$sign,
$payment = [],
$customerIdCard = [],
$itemsToFulfill,
$items,
$deliveryAddress,
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Order/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function execute()
$data['modified'],
'',
isset($data['payment']) ? $data['payment'] : [],
isset($data['customerIdCard']) ? $data['customerIdCard'] : [],
$data['itemsToFulfill'],
$data['items'],
$data['deliveryAddress'],
Expand Down
3 changes: 3 additions & 0 deletions Model/Import/RequestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct(
* @param string $modified
* @param string $sign
* @param mixed $payment
* @param mixed $customerIdCard
* @param mixed $itemsToFulfill
* @param array $items
* @param array $deliveryAddress
Expand Down Expand Up @@ -77,6 +78,7 @@ public function validate(
$modified,
$sign,
$payment,
$customerIdCard,
$itemsToFulfill,
$items,
$deliveryAddress,
Expand All @@ -103,6 +105,7 @@ public function validate(
'name',
'email',
'payment',
'customerIdCard',
'items',
'itemsToFulfill',
'deliveryAddress',
Expand Down
2 changes: 2 additions & 0 deletions Model/OrderImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function import(
$modified,
$sign,
$payment = [],
$customerIdCard = [],
$itemsToFulfill,
$items,
$deliveryAddress,
Expand Down Expand Up @@ -129,6 +130,7 @@ public function import(
$modified,
$sign,
$payment,
$customerIdCard,
$itemsToFulfill,
$items,
$deliveryAddress,
Expand Down
13 changes: 9 additions & 4 deletions Model/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ public function processImport($data)
$order->getPayment()->setAdditionalInformation('merchant_reference', $data['payment']['details']['merchantReference']);
}

$order
->setWalkthechatId($data['id'])
->setWalkthechatName($data['name'])
->setEmailSent(0);
$order->setEmailSent(0);

$this->orderRepository->save($order);

Expand Down Expand Up @@ -401,6 +398,14 @@ protected function initQuote(array $data)
}

$quote = $this->cartRepository->get($cartId);

$quote->setWalkthechatId($data['id']);
$quote->setWalkthechatName($data['name']);

if (isset($data['customerIdCard']['number'])) {
$quote->setWalkthechatCustomerIdNumber($data['customerIdCard']['number']);
$quote->setWalkthechatCustomerIdName($data['customerIdCard']['name']);
}

if (!$customer->getId()) {
$quote->setCustomerEmail($data['id'].'@walkthechat.com');
Expand Down
34 changes: 34 additions & 0 deletions Observer/QuoteSubmitBefore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* @package Walkthechat\Walkthechat
*
* @author WalktheChat <info@walkthechat.com>
* @copyright 2021 Walkthechat
*
* @license See LICENSE.txt for license details.
*/

namespace Walkthechat\Walkthechat\Observer;

/**
* Class QuoteSubmitBefore
*
* @package Walkthechat\Walkthechat\Observer
*/
class QuoteSubmitBefore implements \Magento\Framework\Event\ObserverInterface
{
/**
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$quote = $observer->getQuote();
$order = $observer->getOrder();

$order->setData(\Walkthechat\Walkthechat\Helper\Data::ATTRIBUTE_CODE, $quote->getData(\Walkthechat\Walkthechat\Helper\Data::ATTRIBUTE_CODE));
$order->setData(\Walkthechat\Walkthechat\Helper\Data::ATTRIBUTE_NAME_CODE, $quote->getData(\Walkthechat\Walkthechat\Helper\Data::ATTRIBUTE_NAME_CODE));
$order->setData('walkthechat_customer_id_number', $quote->getData('walkthechat_customer_id_number'));
$order->setData('walkthechat_customer_id_name', $quote->getData('walkthechat_customer_id_name'));
}
}
85 changes: 85 additions & 0 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public function upgrade(
if (version_compare($context->getVersion(), '1.7.3', '<')) {
$this->addVariantVisibilityToInventoryTable($installer);
}

if (version_compare($context->getVersion(), '1.8.0', '<')) {
$this->createWalkTheChatQuoteAttributes($installer);
$this->addCustomerIDAttributesToOrderAndQuote($installer);
}
}

/**
Expand Down Expand Up @@ -724,4 +729,84 @@ public function addVariantVisibilityToInventoryTable(\Magento\Framework\Setup\Sc
);
}
}

/**
* Add walkthechat attributes to the quote table
*
* @param \Magento\Framework\Setup\SchemaSetupInterface $installer
*/
protected function createWalkTheChatQuoteAttributes(\Magento\Framework\Setup\SchemaSetupInterface $installer)
{
$connection = $installer->getConnection();

$connection->addColumn(
$installer->getTable('quote'),
\Walkthechat\Walkthechat\Helper\Data::ATTRIBUTE_CODE,
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
'comment' => 'WalkTheChat ID',
]
);

$connection->addColumn(
$installer->getTable('quote'),
\Walkthechat\Walkthechat\Helper\Data::ATTRIBUTE_NAME_CODE,
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
'comment' => 'WalkTheChat Name',
]
);
}

/**
* Add walkthechat customer ID attributes to quote and order tables
*
* @param \Magento\Framework\Setup\SchemaSetupInterface $installer
*/
protected function addCustomerIDAttributesToOrderAndQuote(\Magento\Framework\Setup\SchemaSetupInterface $installer)
{
$connection = $installer->getConnection();

$connection->addColumn(
$installer->getTable('quote'),
'walkthechat_customer_id_number',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
'comment' => 'WalkTheChat Customer ID Number',
]
);

$connection->addColumn(
$installer->getTable('quote'),
'walkthechat_customer_id_name',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
'comment' => 'WalkTheChat Customer ID Name',
]
);

$connection->addColumn(
$installer->getTable('sales_order'),
'walkthechat_customer_id_number',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
'comment' => 'WalkTheChat Customer ID Number',
]
);

$connection->addColumn(
$installer->getTable('sales_order'),
'walkthechat_customer_id_name',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
'comment' => 'WalkTheChat Customer ID Name',
]
);
}
}
3 changes: 3 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@
<event name="walkthechat_reset_images">
<observer name="walkthechat_reset_images" instance="Walkthechat\Walkthechat\Observer\ResetImages" />
</event>
<event name="sales_model_service_quote_submit_before">
<observer name="walkthechat_sales_model_service_quote_submit_before" instance="Walkthechat\Walkthechat\Observer\QuoteSubmitBefore" />
</event>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Walkthechat_Walkthechat" setup_version="1.7.3" />
<module name="Walkthechat_Walkthechat" setup_version="1.8.0" />
</config>
10 changes: 10 additions & 0 deletions view/adminhtml/templates/order/view/walkthechat.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@
<th><?= $block->escapeHtml(__('WalkTheChat ID')) ?></th>
<td><?= $block->escapeHtml($order->getWalkthechatName()) ?></td>
</tr>
<?php if ($order->getWalkthechatCustomerIdNumber()): ?>
<tr>
<th><?= $block->escapeHtml(__('Customer ID Card Name')) ?></th>
<td><?= $block->escapeHtml($order->getWalkthechatCustomerIdName()) ?></td>
</tr>
<tr>
<th><?= $block->escapeHtml(__('Customer ID Card Number')) ?></th>
<td><?= $block->escapeHtml($order->getWalkthechatCustomerIdNumber()) ?></td>
</tr>
<?php endif ?>
<?php endif ?>