Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the column as a field on Magento order information endpoint #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
41 changes: 41 additions & 0 deletions CustomBoldCommentPlugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace Bold\OrderComment\Plugin;
use Magento\Sales\Api\Data\OrderExtensionFactory;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderSearchResultInterface;
use Magento\Sales\Api\OrderRepositoryInterface;

class CustomBoldCommentPlugin
{

const FIELD_NAME = 'bold_order_comment';
protected $extensionFactory;

public function __construct(OrderExtensionFactory $extensionFactory)
{
$this->extensionFactory = $extensionFactory;
}

public function afterGet(OrderRepositoryInterface $subject, OrderInterface $order)
{
$customBoldComments = $order->getData(self::FIELD_NAME);
$extensionAttributes = $order->getExtensionAttributes();
$extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create();
$extensionAttributes->setBoldOrderComment($customBoldComments);
$order->setExtensionAttributes($extensionAttributes);
return $order;
}

public function afterGetList(OrderRepositoryInterface $subject, OrderSearchResultInterface $searchResult)
{
$orders = $searchResult->getItems();
foreach ($orders as &$order) {
$customBoldComments = $order->getData(self::FIELD_NAME);
$extensionAttributes = $order->getExtensionAttributes();
$extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create();
$extensionAttributes->setBoldOrderComment($customBoldComments);
$order->setExtensionAttributes($extensionAttributes);
}
return $searchResult;
}
}
7 changes: 6 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
<type name="Magento\Sales\Api\OrderRepositoryInterface">
<plugin name="bold_load_ordercomment" type="Bold\OrderComment\Plugin\Model\Order\LoadOrderComment"/>
</type>
</config>

<type name="Magento\Sales\Api\OrderRepositoryInterface">
<plugin name="bold_order_comment_add_order_extension_attribute"
type="Bold\OrderComment\Plugin\CustomBoldCommentPlugin" />
</type>
</config>
5 changes: 5 additions & 0 deletions i18n/es_ES.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"Do you have any comments regarding the order?","¿Tienes algún comentario para agregar al pedido?"
"Enter your comment...","Ingrese su comentario..."
"Order Comment","Comentario del pedido"
"The order comment could not be saved","El comentario del pedido no pudo ser almacenado"
"Cart %1 doesn't contain products","El carrito %1 no contiene productos"