add cart test

This commit is contained in:
Kerim 2023-06-21 02:44:33 +05:00
parent 2f42f6714a
commit 0c864febe0
7 changed files with 405 additions and 23 deletions

View File

@ -3,7 +3,8 @@
namespace Romanah\Bagisto\Components;
use Cms\Classes\ComponentBase;
use Illuminate\Support\Facades\Http;
// use Illuminate\Support\Facades\Http;
use October\Rain\Network\Http;
use Redirect;
use Flash;
use Session as SessionP;
@ -53,35 +54,32 @@ class Session extends ComponentBase
function onAddCart()
{
$getToken = SessionP::get('nurgulToken');
$data = post();
// $response = Http::withHeaders([
// 'Authorization' => $getToken,
// 'Content-Type' => 'application/json'
// ])->post('https://nurgul.com.tm/app/api/customer/cart/add/'.$data["product_id"], [
// 'product_id' => $data["product_id"],
// 'quantity' => $data["quantity"]
// ]);
$data = [
'product_id' => $data["product_id"],
'quantity' => $data["quantity"]
];
$dataInput = post();
$response = Http::post('http://nurgul.com.tm/app/api/customer/cart/add/'.$data["product_id"], function ($http) use($getToken, $data) {
$response = Http::post('http://nurgul.com.tm/app/api/customer/cart/add/'.$dataInput["product_id"], function ($http) use($getToken, $dataInput) {
// $http->header('Content-Type', 'application/json');
$http->header('Authorization', 'Bearer '.$getToken);
$http->header('Accept', 'application/json');
$data = json_encode($data);
// $data = $dataProd;
$data = [
$http->data("product_id", $dataInput["product_id"]),
$http->data("quantity", $dataInput["quantity"]),
];
$http->setOption(CURLOPT_POSTFIELDS, $data);
$http->setOption(CURLOPT_POSTFIELDS, json_encode($data));
});
$dataqq = json_decode($response);
return $dataqq;
if (!empty($dataqq)) {
Flash::success("Üstünlikli Sebede Goşuldy");
return redirect()->refresh();
} elseif (empty($dataqq)) {
Flash::error('Ýalňyşlyk Ýüze Çykdy!!!');
return redirect()->refresh();
}
}
}

135
themes/nurgul/layouts/mainN.htm Executable file
View File

@ -0,0 +1,135 @@
[staticMenu]
code = "top-menu"
[session]
==
<?php
function onStart(){
$this['nurgulToken'] = Session::get('nurgulToken');
$this['user_name'] = Session::get('name');
$this['user_phone'] = Session::get('phone');
}
?>
==
<!doctype html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{this.page.title}}</title>
<meta name="robots" content="noindex, follow" />
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Place favicon.png in the root directory -->
<link rel="shortcut icon" href="{{'assets/img/favicon.png'|theme}}" type="image/x-icon" />
<!-- Font Icons css -->
<link rel="stylesheet" href="{{'assets/css/font-icons.css'|theme}}">
<!-- plugins css -->
<link rel="stylesheet" href="{{'assets/css/plugins.css'|theme}}">
<!-- Main Stylesheet -->
<link rel="stylesheet" href="{{'assets/css/style.css'|theme}}">
<!-- Responsive css -->
<link rel="stylesheet" href="{{'assets/css/responsive.css'|theme}}">
{% styles %}
</head>
<body>
{% flash %}
<p data-control="flash-message" class="flash-message fade {{ type }}" data-interval="5">
{{ message }}
</p>
{% endflash %}
<!-- Body main wrapper start -->
<div class="body-wrapper">
{% partial 'header' %}
{% partial 'cart' %}
{% partial 'mobile-menu' %}
{% partial 'overlay' %}
{% page %}
{% partial 'footer' %}
{% partial 'modals' %}
</div>
<!-- Body main wrapper end -->
<!-- preloader area start -->
<div class="preloader d-none" id="preloader">
<div class="preloader-inner">
<div class="spinner">
<div class="dot1"></div>
<div class="dot2"></div>
</div>
</div>
</div>
<!-- preloader area end -->
<!-- All JS Plugins -->
<script src="{{'assets/jquery.js'|theme}}"></script>
<script src="{{'assets/js/plugins.js'|theme}}"></script>
<!-- Main JS -->
<script src="{{'assets/js/main.js'|theme}}"></script>
<script>
$('#loader_add').hide();
function addToCartq(prodId, qty) {
$(document).ready(function (){
var product = {};
product.product_id = prodId;
product.quantity = qty;
console.log(String('Bearer {{nurgulToken}}'));
console.log(prodId);
console.log(qty);
console.log(JSON.stringify(product));
$.ajax({
async: true,
url: 'https://nurgul.com.tm/app/api/customer/cart/add/' + String(prodId),
type: 'POST',
headers: { Authorization: 'Bearer {{nurgulToken}}' },
processData: false,
contentType: false,
data: JSON.stringify(product),
dataType: 'json',
success: function (data) {
console.log(data);
oc.flashMsg({
message: "{{'added.cart.success'|_}}",
type: 'success',
interval: 3
});
},
error: function (data) {
console.log(data);
}
});
})
// var fd = new FormData();
// fd.append('phone', phone);
}
</script>
{% framework extras %}
{% scripts %}
</body>
</html>

View File

@ -1,5 +1,5 @@
url = "/"
layout = "main"
layout = "mainN"
title = "Home"
[products]
@ -35,5 +35,3 @@ title = "Home"
{% partial 'home/brand' %}

View File

@ -0,0 +1,48 @@
{% put scripts %}
<script>
$('#loader_add').hide();
function addToCartq(prodId, qty) {
$(document).on('ajaxSetup', function (event, context) {
var product = {};
product.product_id = prodId;
product.quantity = qty;
console.log(String('Bearer {{token}}'));
console.log(prodId);
console.log(qty);
console.log(JSON.stringify(product));
$.ajax({
async: true,
url: 'https://nurgul.com.tm/app/api/customer/cart/add/' + String(prodId),
type: 'POST',
headers: { Authorization: 'Bearer {{token}}' },
processData: false,
contentType: false,
data: JSON.stringify(product),
dataType: 'json',
success: function (data) {
console.log(data);
oc.flashMsg({
message: "{{'added.cart.success'|_}}",
type: 'success',
interval: 3
});
},
error: function (data) {
console.log(data);
}
});
})
// var fd = new FormData();
// fd.append('phone', phone);
}
</script>
{% endput %}

View File

@ -0,0 +1,37 @@
{% put scripts %}
<script>
getCart();
// console.log("qqq");
function getCart(query, limit) {
console.log(query);
$(document).ready(function () {
$.ajax({
url: `https://nurgul.com.tm/app/api/customer/cart`,
type: 'GET',
dataType: 'json',
beforeSend: function () {
$('#products_{{id}}').hide();
$('#loader_{{id}}').show();
},
success: function (data, textStatus, xhr) {
$('#loader_{{id}}').hide(500);
$('#products_{{id}}').show(500);
// console.log(data.data);
var products = data.data;
for (var product of products) {
// console.log(product.hasOwnProperty('special_price'));
$('#products_{{id}}').append(productCard(product));
}
},
error: function (xhr, textStatus, errorThrown) {
console.log('Error in Operation');
}
});
});
}
</script>
{% endput %}

View File

@ -42,7 +42,7 @@
</a>
</li>
<li class="add-to-cart">
<a ` + ('{{nurgulToken}}' == "" ? `href='/login'` : `href="javascrip:;" data-request="onAddCart" data-request-data="product_id: `+ product.id +`, quantity: 1"`) + ` title="Add to Cart" >
<a ` + ('{{nurgulToken}}' == "" ? `href='/login'` : `href='javascript:;' onClick='addToCartq(`+product.id+`,`+`1`+`)'`) + ` title="Add to Cart" >
<span class="cart-text d-none d-xl-block">{{add}}</span>
<span class="d-block d-xl-none"><i class="icon-handbag"></i></span>
</a>

View File

@ -0,0 +1,166 @@
{% put scripts %}
<script>
function productCard(product) {
var product_str = JSON.stringify(product);
var card = `<div class="col-lg-3 col-md-4 col-sm-6 col-6">
<div class="ltn__product-item text-center">
<div class="product-img">` +
(product.images.length > 0 ?
`<a href="/product/detail/` + product.id + `">
<img src="`+ product.images[0].original_image_url + `" alt="Nurgul ` + product.name + `" style="width: 400px;height: 280px;object-fit: fill;">
</a>
`
:
`<a href="/product/detail/` + product.id + `">
<img src="{{'assets/no_img.jpg'|theme}}" alt="Nurgul `+ product.name + `" style="width: 400px;height: 280px;object-fit: fill;">
</a>
`
)
+
(product.hasOwnProperty('special_price') ?
`<div class="product-badge">
<ul>
<li class="badge-2">{{'product.badge.discount'|_}}</li>
</ul>
</div>`
:
``
)
+
`<div class="product-hover-action product-hover-action-2">
<ul>
<li>`+
"<a href='#' onClick='setModal(" + product_str + ")' title='Quick View' data-bs-toggle='modal' data-bs-target='#quick_view_modal'>"
+ `<i class="icon-magnifier"></i>
</a>
</li>
<li class="add-to-cart">
<a ` + ('{{nurgulToken}}' == "" ? `href='/login'` : `href="javascrip:;" data-request="onAddCart" data-request-data="product_id: `+ product.id +`, quantity: 1"`) + ` title="Add to Cart" >
<span class="cart-text d-none d-xl-block">{{add}}</span>
<span class="d-block d-xl-none"><i class="icon-handbag"></i></span>
</a>
</li>
<li>
<a href="#" title="Quick View" data-bs-toggle="modal"
data-bs-target="#quick_view_modal">
<i class="icon-shuffle"></i>
</a>
</li>
</ul>
</div>
</div>
<div class="product-info">
<h2 class="product-title"><a href="product-details.html">`+ product.name + `</a></h2>
<div class="product-price">
<span>`+ product.formatted_price + `</span>`
+ (product.hasOwnProperty('special_price') ? `<del>` + product.formatted_regular_price + `</del>` : ``) +
`</div>
</div>
</div>
</div>`;
return card;
}
function productList(product) {
var product_str = JSON.stringify(product);
var list = `
<div class="col-lg-12">
<div class="ltn__product-item">
<div class="product-img">
`
+
(product.images.length > 0 ?
`
<a href="/product/detail/` + product.id + `">
<img style="height: 300px;width: 320px;object-fit: cover;" src="`+ product.images[0].original_image_url + `" alt="Nurgul ` + product.name + `" >
</a>
`
:
`
<a style="height: 300px;width: 320px;object-fit: cover;" href="/product/detail/` + product.id + `">
<img src="{{'assets/no_img.jpg'|theme}}" alt="Nurgul ` + product.name + `" >
</a>
`
)
+
(product.hasOwnProperty('special_price') ?
`<div class="product-badge">
<ul>
<li class="badge-1">{{'product.badge.discount'|_}}</li>
</ul>
</div>
`
:
``
)
+
`</div>
<div class="product-info">
<h2 class="product-title"><a href=""/product/detail/` + product.id + `">` + product.name + `</a></h2>
<div class="product-price">
<span>`+ product.formatted_price + `</span>`
+ (product.hasOwnProperty('special_price') ? `<del>` + product.formatted_regular_price + `</del>` : ``) +
`</div>
<div class="product-brief">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Recusandae asperiores sit odit nesciunt, aliquid, deleniti
non et ut dolorem!</p>
</div>
<div class="product-hover-action product-hover-action-2">
<ul>
<li>
`
+
"<a href='#' onClick='setModal(" + product_str + ")' title='Quick View' data-bs-toggle='modal' data-bs-target='#quick_view_modal'><i class='icon-magnifier'></i></a>"
+
`
</li>
<li class="add-to-cart">
<a href="shop-grid.html#" title="Add to Cart" data-bs-toggle="modal"
data-bs-target="#add_to_cart_modal">
<span class="cart-text d-none d-xl-block">{{add}}</span>
<span class="d-block d-xl-none"><i class="icon-handbag"></i></span>
</a>
</li>
<li>
<a href="shop-grid.html#" title="Quick View" data-bs-toggle="modal"
data-bs-target="#quick_view_modal">
<i class="icon-shuffle"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
`;
return list;
}
</script>
{% endput %}