Skip to content

Commit

Permalink
Add new extension attribute - buyer login (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrzyzewski authored Aug 3, 2020
1 parent b50ce32 commit 2eaa1d9
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Api/Data/CheckoutForm/BuyerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ interface BuyerInterface
public function setFirstName(string $firstName);
public function setLastName(string $lastName);
public function setEmail(string $email);
public function setLogin(string $login);

public function getFirstName(): ?string;
public function getLastName(): ?string;
public function getEmail(): ?string;
public function getLogin(): ?string;

/**
* @param array $rawData
Expand Down
10 changes: 10 additions & 0 deletions Block/OriginOrderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class OriginOrderData extends Template
* @var Registry
*/
private $registry;

/* @var \Magento\Sales\Model\Order */
private $order;

/**
Expand Down Expand Up @@ -54,4 +56,12 @@ public function getExternalID()
// TODO use ExtensionAttributesInterface
return $this->order->getData('external_id');
}

/**
* @return mixed
*/
public function getBuyerLogin()
{
return $this->order->getData('allegro_buyer_login');
}
}
21 changes: 21 additions & 0 deletions Model/Data/CheckoutForm/Buyer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Buyer extends DataObject implements BuyerInterface
const FIRST_NAME_FIELD_NAME = 'first_name';
const LAST_NAME_FIELD_NAME = 'last_name';
const EMAIL_FIELD_NAME = 'email';
const LOGIN_FIELD_NAME = 'login';

/**
* @param string $firstName
Expand All @@ -36,6 +37,14 @@ public function setEmail(string $email)
$this->setData(self::EMAIL_FIELD_NAME, $email);
}

/**
* @param string $login
*/
public function setLogin(string $login)
{
$this->setData(self::LOGIN_FIELD_NAME, $login);
}

/**
* @return string|null
*/
Expand All @@ -60,6 +69,14 @@ public function getEmail(): ?string
return $this->getData(self::EMAIL_FIELD_NAME);
}

/**
* @return string|null
*/
public function getLogin(): ?string
{
return $this->getData(self::LOGIN_FIELD_NAME);
}

/**
* @param array $rawData
*/
Expand All @@ -74,5 +91,9 @@ public function setRawData(array $rawData)
if (isset($rawData['email'])) {
$this->setEmail($rawData['email']);
}

if (isset($rawData['login'])) {
$this->setLogin($rawData['login']);
}
}
}
1 change: 1 addition & 0 deletions Model/OrderImporter/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function execute(CheckoutFormInterface $checkoutForm)
}
$cartExtension->setExternalId($checkoutForm->getId());
$cartExtension->setOrderFrom(OriginOfOrder::ALLEGRO);
$cartExtension->setAllegroBuyerLogin($checkoutForm->getBuyer()->getLogin());
$quote->setExtensionAttributes($cartExtension);

$quote->setAllegroShippingPrice($checkoutForm->getDelivery()->getCost()->getAmount());
Expand Down
1 change: 1 addition & 0 deletions Observer/CopyFieldsFromQuoteToOrderObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
if ($cartExtensions) {
$order->setData('external_id', $cartExtensions->getExternalId());
$order->setData('order_from', $cartExtensions->getOrderFrom());
$order->setData('allegro_buyer_login', $cartExtensions->getAllegroBuyerLogin());
}

$this->objectCopyService->copyFieldsetToTarget('sales_convert_quote', 'to_order', $quote, $order);
Expand Down
3 changes: 3 additions & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
<column xsi:type="varchar" length="255" name="order_from" nullable="true" comment="Where the order comes from"/>
<column xsi:type="varchar" length="255" name="external_id" nullable="true" comment="External order ID"/>
<column xsi:type="varchar" length="255" name="external_guid" nullable="true" comment="External order GUID"/>
<column xsi:type="varchar" length="255" name="allegro_buyer_login" nullable="true" comment="Allegro buyer login"/>
</table>

<table name="sales_order_grid">
<column xsi:type="varchar" length="255" name="order_from" nullable="true" comment="Where the order comes from"/>
<column xsi:type="varchar" length="255" name="external_id" nullable="true" comment="External order ID"/>
<column xsi:type="varchar" length="255" name="external_guid" nullable="true" comment="External order GUID"/>
<column xsi:type="varchar" length="255" name="allegro_buyer_login" nullable="true" comment="Allegro buyer login"/>
</table>

<table name="quote">
<column xsi:type="varchar" length="255" name="order_from" nullable="true" comment="Where the order comes from"/>
<column xsi:type="varchar" length="255" name="external_id" nullable="true" comment="External order ID"/>
<column xsi:type="varchar" length="255" name="external_guid" nullable="true" comment="External order GUID"/>
<column xsi:type="varchar" length="255" name="allegro_buyer_login" nullable="true" comment="Allegro buyer login"/>
</table>

<table name="sales_order_item">
Expand Down
9 changes: 6 additions & 3 deletions etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
"column": {
"order_from": true,
"external_id": true,
"external_guid": true
"external_guid": true,
"allegro_buyer_login": true
}
},
"sales_order_grid": {
"column": {
"order_from": true,
"external_id": true,
"external_guid": true
"external_guid": true,
"allegro_buyer_login": true
}
},
"quote": {
"column": {
"order_from": true,
"external_id": true,
"external_guid": true
"external_guid": true,
"allegro_buyer_login": true
}
},
"sales_order_item": {
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<argument name="columns" xsi:type="array">
<item name="external_id" xsi:type="string">sales_order.external_id</item>
<item name="order_from" xsi:type="string">sales_order.order_from</item>
<item name="allegro_buyer_login" xsi:type="string">sales_order.allegro_buyer_login</item>
</argument>
</arguments>
</virtualType>
Expand Down
2 changes: 2 additions & 0 deletions etc/extension_attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<extension_attributes for="Magento\Quote\Api\Data\CartInterface">
<attribute code="order_from" type="string"/>
<attribute code="external_id" type="string"/>
<attribute code="allegro_buyer_login" type="string"/>
</extension_attributes>

<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
<attribute code="order_from" type="string"/>
<attribute code="external_id" type="string"/>
<attribute code="allegro_buyer_login" type="string"/>
</extension_attributes>

<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
Expand Down
3 changes: 3 additions & 0 deletions etc/fieldset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<field name="order_from">
<aspect name="to_order" />
</field>
<field name="allegro_buyer_login">
<aspect name="to_order" />
</field>
</fieldset>
</scope>
</config>
1 change: 1 addition & 0 deletions i18n/pl_PL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@
"Product SKU","SKU produktu"
"Reservation ID","ID rezerwacji"
"Reservations enabled","Rezerwacje włączone"
"Buyer login","Login kupującego"
2 changes: 2 additions & 0 deletions view/adminhtml/templates/origin_order_data.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
<?= $block->escapeHtml($block->getOrderOrigin()) ?></p>
<p><strong><?= $block->escapeHtml(__('External ID')) ?></strong>:
<?= $block->escapeHtml($block->getExternalId()) ?></p>
<p><strong><?= $block->escapeHtml(__('Buyer login')) ?></strong>:
<?= $block->escapeHtml($block->getBuyerLogin()) ?></p>
<?php endif ?>
9 changes: 9 additions & 0 deletions view/adminhtml/ui_component/sales_order_grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@
</item>
</argument>
</column>
<column name="allegro_buyer_login">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="label" xsi:type="string" translate="true">Buyer login</item>
</item>
</argument>
</column>
</columns>
</listing>

0 comments on commit 2eaa1d9

Please sign in to comment.