shopping-cart 相关问题

用于电子商务的购物车系统,例如在线商店。

如何让代码在购物车中显示保存在cartData中的所有产品,而不是只显示最后一个产品?

我认为解决方案可以修改最后一行 cartItems.innerHTML = cartHTML 以根据 cartData 中的产品数量(基于其长度...

回答 1 投票 0

如何在多次点击加入购物车按钮后保存同一模板的产品数据并显示在购物车文件中?

**代码由3个独立的HTML文件组成,如下所示: ** 1- “SHOP.html”代表商店的 HTML 文件(我们可以从中选择产品) 2-“SPRODUCT.html”一个 HTML 文件...

回答 0 投票 0

带有 API 的 Laravel 8.0 购物车

我正在 Laravel 8.0 中开发电子商务商店应用程序。一项任务是从数据库中检索产品列表并显示在产品刀片页面中。 下面是我的控制器实现 我正在使用 Laravel 8.0 开发电子商务商店应用程序。一项任务是从数据库中检索产品列表并显示在产品刀片页面中。 下面是我的控制器实现 <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Product; class ProductController extends Controller { // public function getProducts(){ $productList = Product::select("*")->where('active_flag','Y')->paginate(10); return response()->json(['productList'=>$productList]); } } 还开发了一个api路由,下面是我的api.php <?php use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use App\Http\Controllers\ProductController; /* |-------------------------------------------------------------------------- | API Routes |-------------------------------------------------------------------------- | | Here is where you can register API routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | is assigned the "api" middleware group. Enjoy building your API! | */ Route::middleware('auth:api')->get('/user', function (Request $request) { return $request->user(); }); Route::get('/products',[ProductController::class, 'getProducts']); 下面是我查看的products.blade页面 @extends('layouts.frontend') @section('content') <div class="container px-6 mx-auto"> <h3 class="text-2xl font-medium text-gray-700">Product List</h3> <div class="grid grid-cols-1 gap-6 mt-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"> <div class="w-full max-w-sm mx-auto overflow-hidden rounded-md shadow-md"> <div class="flex items-end justify-end w-full bg-cover"> </div> <div class="px-5 py-3"> <h3 class="text-gray-700 uppercase">Product Name goes here</h3> <span class="mt-2 text-gray-500">Product price goes here</span> <form action="/" method="POST" enctype="multipart/form-data"> @csrf <input type="hidden" value="product id goes here" name="id"> <input type="hidden" value="product name goes here" name="name"> <input type="hidden" value="product price goes here" name="price"> <input type="hidden" value="product img url goes here" name="image"> <input type="hidden" value="1" name="quantity"> <button class="px-4 py-2 text-white bg-blue-800 rounded">Add To Cart</button> </form> </div> </div> </div> </div> @endsection 现在想通过api获取json结果显示在blade页面。但我不知道该怎么做。在这方面需要一些帮助。希望我的方法是正确的并且符合标准..

回答 0 投票 0

购物车添加商品失败,我该如何解决这个问题?

我有添加到购物车按钮,这个事件是使用 Ajax 调用发送请求到 php 添加到购物车。但是 ajax 调用无法添加到项目。我想知道如何解决这个问题?记录在...

回答 0 投票 0

flutter - 购物车屏幕和总价

我想在按钮上显示总价,像这样“立即购买 $15” $15 是总价,现在我很困惑该怎么做,我试过了,但结果不是我想要的. 你...

回答 0 投票 0

用节点实现购物车

我已经使用 node 和 Postgres 进行电子商务项目一个星期了。请问我真的被手推车困住了。 我有一张购物车物品的桌子 添加到购物车应该会触发一个帖子,我...

回答 0 投票 0

如何重写购物车的JS代码? [关闭]

我正在尝试使用 JS 为购物车编写代码。但是我没有得到他的工作代码。 // 来自 index.html 的购物车的一部分 我正在尝试使用 JS 为购物车编写代码。但是我没有得到他的工作代码。 // 来自 index.html 的部分购物车 <div class="cart-container"> <div class="cart-icon"> <svg id="cart" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <use href="/../img/svg/cart.svg#cart"></use> </svg> <span class="cart-count br-100">0</span> <div class="cart-dropdown"> <!-- dropdown menu items go here --> </div> </div> </div> // index.html 中的一个按钮。 类为“添加到购物车”的所有其他按钮具有相同的代码结构 <button class="add-to-cart br-12 pt-12 pr-16 pb-12 pl-16" data-name="Item name" data-price="$16.00">Buy for $16.00 </button> // 我的购物车.js // Select the "add-to-cart" buttons const addToCartButtons = document.querySelectorAll('.add-to-cart'); // Select the cart elements const cartIcon = document.querySelector('.cart-icon'); const cartCount = document.querySelector('.cart-count'); const cartDropdown = document.querySelector('.cart-dropdown'); const cartEmptyMessage = document.querySelector('.cart-empty-message'); // Set the cart count to 0 by default cartCount.innerText = "0"; // Initialize the item count to 0 let itemCount = 0; // Function to update the cart count and visibility function updateCart() { // Update the cart count element cartCount.innerText = itemCount; // Show or hide the cart dropdown based on the number of items in the cart if (itemCount > 0) { cartDropdown.classList.add('cart-dropdown-show'); cartEmptyMessage.style.display = 'none'; } else { cartDropdown.classList.remove('cart-dropdown-show'); cartEmptyMessage.style.display = 'block'; } } // Add a click event listener to each "add-to-cart" button addToCartButtons.forEach(button => { button.addEventListener('click', () => { // Disable the button to prevent multiple clicks button.disabled = true; // Increment the item count and update the cart itemCount++; updateCart(); // Get the item name, price, and image from the button data attributes const itemName = button.dataset.name; const itemPrice = button.dataset.price; const itemImage = button.dataset.image; // Create the HTML structure for the item const item = document.createElement('div'); item.classList.add('cart-dropdown-item'); item.innerHTML = ` <img src="${itemImage}" alt="Item image" class="item-image"> <div class="item-details"> <div class="item-name">${itemName}</div> <div class="item-price">$${itemPrice}</div> <img src="bin-icon.png" alt="Remove item" class="remove-item"> </div> `; // Add a click event listener to the remove icon to remove the corresponding item from the cart item.querySelector('.remove-item').addEventListener('click', () => { // Remove the item from the cart dropdown item.remove(); // Decrement the item count and update the cart itemCount--; updateCart(); // Re-enable the "add-to-cart" button button.disabled = false; }); // Add the item to the cart dropdown cartDropdown.appendChild(item); }); }); // Add a click event listener to the cart icon to toggle the cart dropdown visibility cartIcon.addEventListener('click', () => { cartDropdown.classList.toggle('cart-dropdown-show'); }); 你能解释一下我失败的地方并告诉我另一个重写代码的解决方案吗?

回答 0 投票 0

如何从购物车模型中获取产品和图片表

我怎样才能用一个查询得到这个树表? 这是我的产品表 Schema::create('products', function (Blueprint $table) { $表->id(); $table->string('slug'); ...

回答 1 投票 0

我想用 PHP 添加产品到购物车

当我点击将产品添加到购物车时,它会显示:“1 = 0”并且没有产品名称或价格等...有人可以帮忙吗? (我应该提到 init.inc 文件有 DB

回答 0 投票 0

在 Woocommerce 购物篮中只允许来自相同父类别的项目

我有 3 个“主”类别,常温、冷藏和冷冻。 Ambient 然后分为 3 个其他类别,食品和饮料、非食品和宠物产品,每个类别都有自己的子类别。我试过了……

回答 1 投票 0

无法自动装配服务“App\Controller\MainController”:方法“__construct()”的参数“$session”

有我的主控制器: 有我的主控制器: <?php namespace App\Controller; use App\Entity\ShopCart; use App\Entity\ShopItem; use App\Repository\ShopItemRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Config\Framework\SessionConfig; use Symfony\Component\HttpFoundation\RequestStack; class MainController extends AbstractController { private SessionInterface $session; /** * @param SessionInterface $session */ public function __construct(SessionInterface $session) { $this->session = $session; $this->session->start(); } public function debug($data) { echo '<pre>' . print_r($data) . '</pre>'; } #[Route('shop/list', name: 'List')] public function shopList(EntityManagerInterface $entityManager, ShopItemRepository $shopItemRepository): Response { $result = $shopItemRepository->findAll(); return $this->render('shop-list.html.twig', [ 'shoes' => $result, ]); } /** * @param int $shopItem * @return Response */ #[Route('/shop/item{id<\d+>}', name: 'shopItem')] public function shopItem(ShopItem $shopItem) { return $this->render('shop-item.html.twig', [ 'title' => $shopItem->getTitle(), 'description' => $shopItem->getDescription(), 'price' => $shopItem->getPrice(), ]); } #[Route('/', name: 'Home')] public function homepage(): Response { return $this->render('homepage.html.twig'); } /** * @param int $shopItem * @return Response */ #[Route('/shop/cart/add/{id<\d+>}', name: 'shopCartAdd')] public function shopCartAdd(ShopItem $shopItem, EntityManagerInterface $entityManager): Response { $sessionId = $this->session->getId(); dd($sessionId); // $shopCart = new ShopCart(); // $shopCart->setShopItem($shopItem); // $shopCart->setSessionId($sessionId); // $shopCart->setCount(1); } #[Route('/shop/cart', name: 'ShopCart')] public function shopCart(): Response { return $this->render('shopCart.html.twig'); } } 当我尝试 dd 时,我收到了 无法自动装配服务“App\Controller\MainController”:方法“__construct()”的参数“$session”需要“Symfony\Component\HttpFoundation\Session\SessionInterface”的实例,但这种类型已被排除在自动装配之外。 使用 Symfony 6.2.7 我尝试更改 Session 或其他服务上的 SessionInterface 但它没有帮助 自 Symfony 5.3 起,SessionInterface 已被弃用(https://symfony.com/blog/new-in-symfony-5-3-session-service-deprecation)。 需要注入RequestStack并调用getSession()方法: public function __construct(RequestStack $requestStack) { // ... $session = $this->requestStack->getSession(); } // ...

回答 1 投票 0

在 MERN 的 POS 应用程序结帐过程后,购物车项目未删除或为空。比如 await cartItems.findAndUpdate({ $set: { cartItems: [] } });

我已经在 MERN 中创建了 POS 销售点应用程序,它运行良好,只是有两个问题。 结帐过程后购物车项目未移除或清空 购物车物品保持不变......

回答 1 投票 0

如何将单元格中单击的按钮上的数据传递到另一个添加到购物车页面的表格视图?

在此输入图片描述在此输入图片描述 导入基金会 导入 UIKit 导入 PanModal 变种总和=“” 类 CustomBottomSheet: UITableViewController { @IBOutlet ...

回答 1 投票 0

将项目从一个 html 页面移动到另一个

如何在不使用或使用 localStorage.set-getItem 的情况下将列表中的项目从一个 html 页面移动到另一个 我正在制作一个电子商务网站。当我的客户点击...的“添加”按钮时

回答 1 投票 0

如何使用 Redux 和 React js 在购物车页面中添加和删除总价

React JS 的开发人员大家好! 我是第一次使用 Redux 和 React Js 并尝试获取购物车中添加和删除的商品的总价,但是当删除一个商品时总价只增加而没有减少。 ...

回答 1 投票 0

数量增加或减少时,总计应该放什么?请帮助我

数量增加或减少时,总计应该放什么?我想发生当用户点击数量增加时总数也增加。我试过一些javascr ...

回答 0 投票 0

PlentyMarkets 的重要问题

两天后我要考试,Plentymarkets 很重要。不幸的是,我几个月来一直在寻找一些未解决的问题。老师,教育机构......

回答 0 投票 0

如果数据库中的条目数不只是为了可读性而改变,为什么要为购物车创建一个新的“CartItem”实体?

无需详细说明,现在我有两个实体:发票和产品。是否值得创建一个新的 CatItem 实体,其字面意思是一个属性“数量”(和关系属性

回答 1 投票 0

从 firestore 读取数据的正确方法,以避免重复数据渲染

我一直在构建一个基于反应的电子商务平台作为个人投资组合项目,使用 firebase 作为后端服务。到目前为止,我已经完成了设置,用户可以创建一个帐户......

回答 0 投票 0

如何最好地实施购物车?

无需详细说明,现在我有两个实体:发票和产品。是否值得创建一个新的 CatItem 实体,其字面意思是一个属性“数量”(和关系属性

回答 0 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.