eo / ecommerce-bundle
基于Sylius和Spree的轻量级且灵活的电商包
dev-master / 1.0.x-dev
2013-09-19 23:51 UTC
Requires
- doctrine/mongodb-odm-bundle: >=2.1.0-dev
- symfony/symfony: >=2.1,<2.4-dev
Requires (Dev)
- eo/symfony-test-edition: dev-master
This package is auto-updated.
Last update: 2024-09-24 00:21:55 UTC
README
一个轻量级且灵活的基于Sylius和Spree的电商包(适用于MongoDB)。
先决条件
此版本的包需要Symfony 2.1+
概念
产品选项
通常您需要对同一产品有不同的选项。例如,考虑一个简单的商店,它销售iPhone和iPad
Products:
1) iPhone (starting from: $649)
Options:
1) iPhone 16GB ($649)
2) iPhone 32GB ($749)
3) iPhone 64GB ($849)
2) iPad (starting from: $499)
Options:
1) iPad 16GB ($499)
1) iPad 32GB ($599)
1) iPad 64GB ($699)
1) iPad 128GB ($799)
要添加选项,您必须首先在您的产品类中实现CustomProductInterface
接口。此接口将为您提供访问3个新字段(选项、变体和价格)。一旦实现,您需要为产品设置一个选项映射
<?php # Your product class use Eo\EcommerceBundle\Document\Option\Option; use Eo\EcommerceBundle\Document\Product\BaseCustomProduct; class AcmeProduct extends BaseCustomProduct { public function getOptions() { // Set product options $model = new Option(); $model->setName('Model'); $model->setMethod('getModels'); return new ArrayCollection(array($model)); } /** * This method should return an ArrayCollection of `OptionInterface` objects * * @return ArrayCollection $optionValues */ public function getModels() { # Implement your custom logic here $models = array(); // 16 GB - $649 $price649 = new Price(); // In some cases you will need to have a price // name for easy identifying and order filtering. $price649->setName("Price name"); $price649->setPrice(64900); $model16gb = new OptionValue(); $model16gb->setName('16GB'); $model16gb->setPrice($price649); $models[] = $model16gb; // 32 GB - $749 $price749 = new Price(); $price749->setName("Price name"); $price749->setPrice(74900); $model32gb = new OptionValue(); $model32gb->setName('32GB'); $model32gb->setPrice($price749); $models[] = $model32gb; // 64 GB - $849 $price849 = new Price(); $price849->setName("Price name"); $price849->setPrice(84900); $model64gb = new OptionValue(); $model64gb->setName('64GB'); $model64gb->setPrice($price849); $models[] = $model64gb; return $models; } }
安装
步骤1:使用composer下载EoEcommerceBundle
在您的composer.json中添加EoEcommerceBundle
{ "require": { "eo/ecommerce-bundle": "dev-master" } }
现在运行以下命令,让composer下载此包
$ php composer.phar update "eo/ecommerce-bundle"
Composer会将此包安装到您的项目的vendor/eo目录下。
步骤2:启用包
在kernel中启用包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Eo\PassbookBundle\EoEcommerceBundle(), ); }