WIP: cart
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use App\Adapters\OcModelCatalogProductAdapter;
|
||||
use App\ApplicationFactory;
|
||||
use Cart\Cart;
|
||||
use Cart\Currency;
|
||||
use Cart\Tax;
|
||||
use Openguru\OpenCartFramework\ImageTool\ImageTool;
|
||||
@@ -60,6 +61,14 @@ class Controllerextensiontgshophandle extends Controller
|
||||
return new ImageTool(DIR_IMAGE, HTTPS_SERVER);
|
||||
});
|
||||
|
||||
$app->bind(\Cart\Cart::class, function () {
|
||||
return $this->cart;
|
||||
});
|
||||
|
||||
$app->bind(DB::class, function () {
|
||||
return $this->db;
|
||||
});
|
||||
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$app->bind('model_checkout_order', function () {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Adapters;
|
||||
|
||||
class OcCartAdapter
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handlers;
|
||||
|
||||
use Cart\Cart;
|
||||
use Openguru\OpenCartFramework\Http\JsonResponse;
|
||||
use Openguru\OpenCartFramework\Http\Request;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\Connections\ConnectionInterface;
|
||||
|
||||
class CheckoutHandler
|
||||
{
|
||||
private Cart $cart;
|
||||
private \DB $connection;
|
||||
|
||||
public function __construct(Cart $cart, \DB $database)
|
||||
{
|
||||
$this->cart = $cart;
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
public function addToCart(Request $request): JsonResponse
|
||||
{
|
||||
$item = $request->json();
|
||||
|
||||
$options = [];
|
||||
|
||||
foreach ($item['options'] as $option) {
|
||||
if (! empty($option['value']) && ! empty($option['value']['product_option_value_id'])) {
|
||||
$options[$option['product_option_id']] = $option['value']['product_option_value_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->cart->add(
|
||||
$item['productId'],
|
||||
$item['quantity'],
|
||||
$options,
|
||||
);
|
||||
|
||||
return new JsonResponse([
|
||||
'data' => $this->cart->getProducts(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkout(Request $request): JsonResponse
|
||||
{
|
||||
$items = $request->json();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$options = [];
|
||||
|
||||
foreach ($item['options'] as $option) {
|
||||
if (! empty($option['value']) && ! empty($option['value']['product_option_value_id'])) {
|
||||
$options[$option['product_option_id']] = $option['value']['product_option_value_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->cart->add(
|
||||
$item['productId'],
|
||||
$item['quantity'],
|
||||
$options,
|
||||
);
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'data' => $items,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Handlers\CategoriesHandler;
|
||||
use App\Handlers\CheckoutHandler;
|
||||
use App\Handlers\HelloWorldHandler;
|
||||
use App\Handlers\OrderCreateHandler;
|
||||
use App\Handlers\ProductsHandler;
|
||||
@@ -11,4 +12,7 @@ return [
|
||||
'order_create' => [OrderCreateHandler::class, 'handle'],
|
||||
|
||||
'categoriesList' => [CategoriesHandler::class, 'index'],
|
||||
|
||||
'checkout' => [CheckoutHandler::class, 'checkout'],
|
||||
'addToCart' => [CheckoutHandler::class, 'addToCart'],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user