Skip to content

Commit 6d0cfb2

Browse files
Merge pull request #89 from xendit/TPI-5400/TPI-5413/invoice-qris
Tpi 5400/tpi 5413/invoice qris
2 parents 1cec783 + 9098f4d commit 6d0cfb2

39 files changed

+159
-1311
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 3.3.0 (2021-11-11)
4+
Improvements:
5+
- Migrate QRIS (QR Codes) to XenInvoice
6+
- Add category on create invoice
7+
38
## 3.2.0 (2021-11-02)
49
Improvements:
510
- Migrate Kredivo to XenInvoice

Xendit/M2Invoice/Block/Checkout/Qrcode.php

-53
This file was deleted.

Xendit/M2Invoice/Controller/Checkout/AbstractAction.php

+33
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Magento\Framework\Stdlib\CookieManagerInterface;
1616
use Magento\Framework\UrlInterface;
1717
use Magento\Sales\Api\OrderRepositoryInterface;
18+
use Magento\Sales\Model\Category;
19+
use Magento\Catalog\Model\CategoryFactory;
1820
use Magento\Sales\Model\Order;
1921
use Magento\Sales\Model\OrderFactory;
2022
use Magento\Store\Model\StoreManagerInterface;
@@ -44,6 +46,11 @@ abstract class AbstractAction extends Action
4446
*/
4547
private $context;
4648

49+
/**
50+
* @var CategoryFactory
51+
*/
52+
private $categoryFactory;
53+
4754
/**
4855
* @var OrderFactory
4956
*/
@@ -143,6 +150,7 @@ abstract class AbstractAction extends Action
143150
* AbstractAction constructor.
144151
* @param Session $checkoutSession
145152
* @param Context $context
153+
* @param CategoryFactory $categoryFactory
146154
* @param OrderFactory $orderFactory
147155
* @param LoggerInterface $logger
148156
* @param Data $dataHelper
@@ -164,6 +172,7 @@ abstract class AbstractAction extends Action
164172
public function __construct(
165173
Session $checkoutSession,
166174
Context $context,
175+
CategoryFactory $categoryFactory,
167176
OrderFactory $orderFactory,
168177
LoggerInterface $logger,
169178
Data $dataHelper,
@@ -187,6 +196,7 @@ public function __construct(
187196

188197
$this->checkoutSession = $checkoutSession;
189198
$this->context = $context;
199+
$this->categoryFactory = $categoryFactory;
190200
$this->orderFactory = $orderFactory;
191201
$this->logger = $logger;
192202
$this->dataHelper = $dataHelper;
@@ -224,6 +234,14 @@ protected function getCheckoutSession()
224234
return $this->checkoutSession;
225235
}
226236

237+
/**
238+
* @return CategoryFactory
239+
*/
240+
protected function getCategoryFactory()
241+
{
242+
return $this->categoryFactory;
243+
}
244+
227245
/**
228246
* @return OrderFactory
229247
*/
@@ -278,6 +296,21 @@ protected function getOrder()
278296
return $this->getOrderById($orderId);
279297
}
280298

299+
/**
300+
* @param $categoryId
301+
* @return Category|null
302+
*/
303+
protected function getCategoryById($categoryId)
304+
{
305+
$category = $this->categoryFactory->create()->loadByIncrementId($categoryId);
306+
307+
if (!$category->getId()) {
308+
return null;
309+
}
310+
311+
return $category;
312+
}
313+
281314
/**
282315
* @param $orderId
283316
* @return Order|null

Xendit/M2Invoice/Controller/Checkout/Invoice.php

+9
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ private function getApiRequestData($order)
7777
foreach ($orderItems as $orderItem) {
7878
$item = [];
7979
$product = $orderItem->getProduct();
80+
$categoryIds = $product->getCategoryIds();
81+
$categories = [];
82+
foreach ($categoryIds as $categoryId) {
83+
$category = $this->getCategoryFactory()->create();
84+
$category->load($categoryId);
85+
$categories[] = (string) $category->getName();
86+
}
87+
$categoryName = implode(', ', $categories);
8088
$item['reference_id'] = $product->getId();
8189
$item['name'] = $product->getName();
90+
$item['category'] = $categoryName ?: 'Uncategorized';
8291
$item['price'] = $product->getPrice();
8392
$item['type'] = 'PRODUCT';
8493
$item['url'] = $product->getProductUrl();

Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Magento\Framework\Controller\ResultFactory;
66
use Magento\Framework\Phrase;
77
use Magento\Sales\Model\Order;
8+
use Magento\Catalog\Model\Category;
89
use Magento\Framework\Exception\LocalizedException;
910
use Zend\Http\Request;
1011

@@ -17,6 +18,7 @@ class InvoiceMultishipping extends AbstractAction
1718
/**
1819
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
1920
*/
21+
2022
public function execute()
2123
{
2224
try {
@@ -67,13 +69,21 @@ public function execute()
6769
'country' => $shippingAddress->getData('country_id') ?: 'ID'
6870
];
6971
$addresses[] = (object) $address;
70-
7172
$orderItems = $order->getAllItems();
7273
foreach ($orderItems as $orderItem) {
7374
$item = [];
7475
$product = $orderItem->getProduct();
76+
$categoryIds = $product->getCategoryIds();
77+
$categories = [];
78+
foreach ($categoryIds as $categoryId) {
79+
$category = $this->getCategoryFactory()->create();
80+
$category->load($categoryId);
81+
$categories[] = (string) $category->getName();
82+
}
83+
$categoryName = implode(', ', $categories);
7584
$item['reference_id'] = $product->getId();
7685
$item['name'] = $product->getName();
86+
$item['category'] = $categoryName ?: 'Uncategorized';
7787
$item['price'] = $product->getPrice();
7888
$item['type'] = 'PRODUCT';
7989
$item['url'] = $product->getProductUrl();

0 commit comments

Comments
 (0)