Skip to content

Commit

Permalink
Merge pull request #89 from xendit/TPI-5400/TPI-5413/invoice-qris
Browse files Browse the repository at this point in the history
Tpi 5400/tpi 5413/invoice qris
  • Loading branch information
kevinalfianto authored Nov 15, 2021
2 parents 1cec783 + 9098f4d commit 6d0cfb2
Show file tree
Hide file tree
Showing 39 changed files with 159 additions and 1,311 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 3.3.0 (2021-11-11)
Improvements:
- Migrate QRIS (QR Codes) to XenInvoice
- Add category on create invoice

## 3.2.0 (2021-11-02)
Improvements:
- Migrate Kredivo to XenInvoice
Expand Down
53 changes: 0 additions & 53 deletions Xendit/M2Invoice/Block/Checkout/Qrcode.php

This file was deleted.

33 changes: 33 additions & 0 deletions Xendit/M2Invoice/Controller/Checkout/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\UrlInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Category;
use Magento\Catalog\Model\CategoryFactory;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\OrderFactory;
use Magento\Store\Model\StoreManagerInterface;
Expand Down Expand Up @@ -44,6 +46,11 @@ abstract class AbstractAction extends Action
*/
private $context;

/**
* @var CategoryFactory
*/
private $categoryFactory;

/**
* @var OrderFactory
*/
Expand Down Expand Up @@ -143,6 +150,7 @@ abstract class AbstractAction extends Action
* AbstractAction constructor.
* @param Session $checkoutSession
* @param Context $context
* @param CategoryFactory $categoryFactory
* @param OrderFactory $orderFactory
* @param LoggerInterface $logger
* @param Data $dataHelper
Expand All @@ -164,6 +172,7 @@ abstract class AbstractAction extends Action
public function __construct(
Session $checkoutSession,
Context $context,
CategoryFactory $categoryFactory,
OrderFactory $orderFactory,
LoggerInterface $logger,
Data $dataHelper,
Expand All @@ -187,6 +196,7 @@ public function __construct(

$this->checkoutSession = $checkoutSession;
$this->context = $context;
$this->categoryFactory = $categoryFactory;
$this->orderFactory = $orderFactory;
$this->logger = $logger;
$this->dataHelper = $dataHelper;
Expand Down Expand Up @@ -224,6 +234,14 @@ protected function getCheckoutSession()
return $this->checkoutSession;
}

/**
* @return CategoryFactory
*/
protected function getCategoryFactory()
{
return $this->categoryFactory;
}

/**
* @return OrderFactory
*/
Expand Down Expand Up @@ -278,6 +296,21 @@ protected function getOrder()
return $this->getOrderById($orderId);
}

/**
* @param $categoryId
* @return Category|null
*/
protected function getCategoryById($categoryId)
{
$category = $this->categoryFactory->create()->loadByIncrementId($categoryId);

if (!$category->getId()) {
return null;
}

return $category;
}

/**
* @param $orderId
* @return Order|null
Expand Down
9 changes: 9 additions & 0 deletions Xendit/M2Invoice/Controller/Checkout/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,17 @@ private function getApiRequestData($order)
foreach ($orderItems as $orderItem) {
$item = [];
$product = $orderItem->getProduct();
$categoryIds = $product->getCategoryIds();
$categories = [];
foreach ($categoryIds as $categoryId) {
$category = $this->getCategoryFactory()->create();
$category->load($categoryId);
$categories[] = (string) $category->getName();
}
$categoryName = implode(', ', $categories);
$item['reference_id'] = $product->getId();
$item['name'] = $product->getName();
$item['category'] = $categoryName ?: 'Uncategorized';
$item['price'] = $product->getPrice();
$item['type'] = 'PRODUCT';
$item['url'] = $product->getProductUrl();
Expand Down
12 changes: 11 additions & 1 deletion Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Phrase;
use Magento\Sales\Model\Order;
use Magento\Catalog\Model\Category;
use Magento\Framework\Exception\LocalizedException;
use Zend\Http\Request;

Expand All @@ -17,6 +18,7 @@ class InvoiceMultishipping extends AbstractAction
/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
*/

public function execute()
{
try {
Expand Down Expand Up @@ -67,13 +69,21 @@ public function execute()
'country' => $shippingAddress->getData('country_id') ?: 'ID'
];
$addresses[] = (object) $address;

$orderItems = $order->getAllItems();
foreach ($orderItems as $orderItem) {
$item = [];
$product = $orderItem->getProduct();
$categoryIds = $product->getCategoryIds();
$categories = [];
foreach ($categoryIds as $categoryId) {
$category = $this->getCategoryFactory()->create();
$category->load($categoryId);
$categories[] = (string) $category->getName();
}
$categoryName = implode(', ', $categories);
$item['reference_id'] = $product->getId();
$item['name'] = $product->getName();
$item['category'] = $categoryName ?: 'Uncategorized';
$item['price'] = $product->getPrice();
$item['type'] = 'PRODUCT';
$item['url'] = $product->getProductUrl();
Expand Down
Loading

0 comments on commit 6d0cfb2

Please sign in to comment.