定制 dynamic/silverstripe-product-wishlist 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dynamic/silverstripe-product-wishlist

Composer 安装命令:

composer require dynamic/silverstripe-product-wishlist

包简介

adds a product wish list to your website

关键字:

README 文档

README

Build Status codecov Scrutinizer Code Quality Build Status

product-wishlist

Allows users to create and manage a wish list on a website.

Requirements

  • silverstripe/recipe-cms ^4.0
  • dynamic/viewable-dataobject ^2.0
  • dynamic/silverstripe-additional-formfields ^2.0
  • dynamic/silverstripe-manageable-dataobject ^2.0

Installation

composer require dynamic/silverstripe-product-wishlist

Example usage

This module was not hooked up with any particular module that adds products to allow flexibility. The examples here will use FoxyStripe.

ProductWishList Extension

A product relation must be added to Dynamic\Wishlist\Model\ProductWishList through a DataExtension.

Dynamic\Wishlist\Model\ProductWishList:
  extensions:
    - Foo\Bar\ORM\WishListExtension
<?php

namespace Foo\Bar\ORM;

use Dynamic\FoxyStripe\Page\ProductPage;
use SilverStripe\ORM\DataExtension;

class WishListExtension extends DataExtension
{
    /**
     * @var array
     */
    private static $many_many = [
        'Products' => ProductPage::class,
    ];
}

Product Relation

The Product must also have a reciprocal relation to wishlists.

Dynamic\FoxyStripe\Page\ProductPage:
  extensions:
    - Foo\Bar\ORM\ProductExtension
<?php

namespace Foo\Bar\ORM;

use Dynamic\Wishlist\Model\ProductWishList;

class ProductExtension extends DataExtension
{
    /**
     * @var array
     */
    private static $belongs_many_many = [
        'WishLists' => ProductWishList::class,
    ];
}

WishList Form

The ProductControllerExtension should be applied to the controller that handles showing a product.

Dynamic\FoxyStripe\Page\ProductPageController:
  extensions:
    - Dynamic\Wishlist\Extensions\ProductControllerExtension

The form can be passed a product id to avoid using the current controller's page id. The form will not show if the user is not logged in.

AddToWishListForm and RemoveFromWishListForm

The only real difference between these forms are the actions the forms call and an extra class.

updateWishLists

An extension point for updating the wishlists visible in the dropdown field. It is passed a DataList of the wishlists associated with the current user.

/**
 * @param SilverStripe\ORM\DataList $lists
 */
public function updateWishLists($lists)
{
    // Stuff here
}
updateFields

An extension point for updating the fields for the form. It is passed a FieldList and an int.

/**
 * @param SilverStripe\Forms\FieldList $fields
 * @param int $productID
 */
public function updateFields($fields, $productID)
{
    // Stuff here
}
updateActions

An extension point for updating the actions for the form. It is passed a FieldList and an int.

/**
 * @param SilverStripe\Forms\FieldList $actions
 * @param int $productID
 */
public function updateActions($actions, $productID)
{
    // Stuff here
}

WishList Form Handling

Handling the addToWishList and removeFromWishList actions is not included by default. The example implementations should be on a controller, or an extension applied to a controller.

addToWishList Example

/**
 * @param $data
 * @param \SilverStripe\Forms\Form $form
 * @return \SilverStripe\Control\HTTPResponse
 * @throws \Exception
 */
public function addToWishList($data, Form $form)
{
    /** @var ProductWishList|\Foo\Bar\Extension\WishListExtension $list */
    $list = ProductWishList::get()->filter([
        'ID' => $data['List'],
    ])->first();

    $list->Products()->add($data['ProductID']);

    return $this->owner->redirectBack();
}

removeFromWishList Example

/**
 * @param $data
 * @param \SilverStripe\Forms\Form $form
 * @return \SilverStripe\Control\HTTPResponse
 * @throws \Exception
 */
public function removeFromWishList($data, Form $form)
{
    /** @var ProductWishList|\Foo\Bar\Extension\WishListExtension $list */
    $list = ProductWishList::get()->filter([
        'ID' => $data['List'],
    ])->first();

    $list->Products()->removeByID($data['ProductID']);

    return $this->owner->redirectBack();
}

Documentation

See the docs/en folder.

统计信息

  • 总下载量: 64
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 5
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-10-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固