小编Kod*_*ant的帖子

Woocommerce | 通过 Ajax 清除购物车

我正在尝试设置一个 AJAX 函数来清除我的购物车

HTML

<a onclick="clearCart(this)" data-href="/product-page/" data-productID="182">Go to Product</a>
Run Code Online (Sandbox Code Playgroud)

JavaScript

function clearCart(d) {
    jQuery(document).ready(function($) {
        var productID = d.getAttribute("data-productID");
        $.ajax({
            url: "addtocart.php",
            data: {productID: productID},
            type: "post",
            success: function(output) {
                window.location = d.getAttribute("data-href");
                //alert(output);
            }
        });
    });
}
Run Code Online (Sandbox Code Playgroud)

PHP

if(isset($_POST['productID']) && !empty($_POST['productID'])) {   
    global $woocommerce;
    $woocommerce->cart->empty_cart();
    //echo $_POST['productID'];
}
Run Code Online (Sandbox Code Playgroud)

结果

  • 由第三行 PHP 引起的内部服务器错误
  • 警报 var 输出正在工作(检查注释掉的代码)

解决方案

我自己弄明白了,@MirzaP 也提供了一些帮助

JS

      function clearCart(d) {
            jQuery.post(
                "https://dercampus.ch/wp-admin/admin-ajax.php", 
                //ajaxurl, 
                {
                    "action": "clearcart",
                    "data":   d.getAttribute("data-productid")
                }, 
                function(){
                    window.location = d.getAttribute("data-href");
                }
            );
        } …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax wordpress woocommerce

5
推荐指数
1
解决办法
5273
查看次数

扩展 HTMLElement 原型

我正在尝试在 中扩展 HTMLElement 对象的原型main.ts,以便我可以在整个 Angular 6 项目中使用它。

但我得到了Property 'fadeOut' does not exist on type 'HTMLElement'.

HTMLElement.prototype.fadeOut = function(duration: number = 300): Promise<void> {
  const keyframes: AnimationKeyFrame[] = [{ opacity: 1 }, { opacity: 0 }];
  return new Promise(resolve => {
    const animation: Animation = this.animate(keyframes, duration);
    animation.onfinish = () => resolve();
  });
};
Run Code Online (Sandbox Code Playgroud)

HTMLElement.prototype.fadeOut = function(duration: number = 300): Promise<void> {
  const keyframes: AnimationKeyFrame[] = [{ opacity: 1 }, { opacity: 0 }];
  return new Promise(resolve …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

4
推荐指数
1
解决办法
1484
查看次数

“在 Angular|Ionic 中找不到 [自定义组件] 的组件工厂”

我正在使用带有延迟加载页面的 Ionic 3。尝试在页面内的组件中显示模式时,出现以下错误:

No component factory found for CourseEditorComponent. Did you add it to @NgModule.entryComponents?
Run Code Online (Sandbox Code Playgroud)

正如你可以看到下面下来,我已经添加了CourseEditorComponent作为entryComponent到courses.modules.ts,其中得到由进口dashboard.modules.ts

我对 Angular/Ionic 中使用自定义 entryComponents 的方式有什么误解吗?

等级制度

DashboardPage
-CoursesComponent
--CourseEditorComponent
--CourseCreatorComponent
-InstructorsComponent
Run Code Online (Sandbox Code Playgroud)

模块

仪表板.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { DashboardPage } from './dashboard';
import { CoursesModule } from "./courses/courses.module";

@NgModule({
  declarations: [
    DashboardPage
  ],
  imports: [
    IonicPageModule.forChild(DashboardPage),
    CoursesModule
  ],
})
export class DashboardPageModule {}
Run Code Online (Sandbox Code Playgroud)

course.module.ts

import { NgModule } from '@angular/core';
import …
Run Code Online (Sandbox Code Playgroud)

ionic-framework ionic2 ionic3 angular

2
推荐指数
1
解决办法
4290
查看次数

使用 Firestore 在云函数中获取/添加文档

当用户购买产品并按条带支付时,我在集成自动化工作流程方面遇到了一些困难。我正在使用Firestore和 Cloud Functions。

工作流程

  1. 用户通过 Stripe Checkout.js 购买产品
  2. 付款存储在“付款”集合中

    { product:<uid of the product> '...', user:<uid of the user> '..', method: 'stripe', token:< Stripe token> {..} }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 触发云功能(用于收款的 onWrite)

  4. TODO:从“产品”中获取产品 DocRef(检索产品的价格)
  5. TODO:将文档添加到“用户”集合的文档内的“购买”集合

  6. 收费付款

我已经实现了这个工作流程,除了第 4 步和第 5 步,因为我不知道如何在 Cloud Functions 中从 Firestore 检索和添加 DocRef(Firebase Docs 提供了很多关于它如何与 RT 数据库配合使用的示例)

函数/index.js

exports.stripeCharge = functions.firestore
  .document('/payments/{payment}')
  .onWrite(event => {
    const paymentId = event.params.payment;
    const payment = event.data.data();
    if (!payment || payment.method !== 'stripe' || payment.charge) return;
    // 4. Get Product's Price …
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-functions google-cloud-firestore

1
推荐指数
1
解决办法
4697
查看次数