├── commerce_examples.commerce_adjustment_types.yml
├── config
└── install
│ ├── commerce_product.commerce_product_attribute.size.yml
│ ├── commerce_product.commerce_product_attribute.color.yml
│ ├── commerce_product.commerce_product_variation_type.ebook.yml
│ ├── commerce_product.commerce_product_type.ebook.yml
│ ├── commerce_product.commerce_product_type.t_shirt.yml
│ ├── commerce_product.commerce_product_variation_type.t_shirt.yml
│ ├── commerce_order.commerce_order_type.digital.yml
│ ├── commerce_order.commerce_order_type.b2b.yml
│ ├── commerce_payment.commerce_payment_gateway.example_on_site.yml
│ ├── field.storage.commerce_product_variation.weight.yml
│ ├── field.storage.commerce_product_variation.attribute_color.yml
│ ├── field.storage.commerce_product_variation.attribute_size.yml
│ ├── field.field.commerce_product.ebook.body.yml
│ ├── field.field.commerce_product.t_shirt.body.yml
│ ├── field.field.commerce_product.ebook.stores.yml
│ ├── field.field.commerce_product.t_shirt.stores.yml
│ ├── field.field.commerce_order.digital.order_items.yml
│ ├── field.field.commerce_product_variation.t_shirt.weight.yml
│ ├── core.entity_view_display.commerce_product_attribute_value.color.default.yml
│ ├── field.field.commerce_product.ebook.variations.yml
│ ├── field.field.commerce_product.t_shirt.variations.yml
│ ├── field.storage.commerce_product_attribute_value.field_swatch.yml
│ ├── field.field.commerce_product_variation.t_shirt.attribute_size.yml
│ ├── field.field.commerce_product_variation.t_shirt.attribute_color.yml
│ ├── core.entity_view_display.commerce_product.ebook.default.yml
│ ├── core.entity_view_display.commerce_product.t_shirt.default.yml
│ ├── core.entity_view_display.commerce_product_variation.ebook.default.yml
│ ├── field.field.commerce_product_attribute_value.color.field_swatch.yml
│ ├── core.entity_view_display.commerce_product_variation.t_shirt.default.yml
│ ├── core.entity_form_display.commerce_order.digital.default.yml
│ ├── core.entity_form_display.commerce_product_variation.t_shirt.default.yml
│ ├── core.entity_form_display.commerce_product.t_shirt.default.yml
│ └── user.role.store_admin.yml
├── data
├── demo_ebooks.csv
├── demo_t_shirts.csv
└── fillerama.json
├── migrations
├── commerce_examples_product_attribute_size.yml
├── commerce_examples_product_attribute_color.yml
├── commerce_examples_product_variation_import_ebook.yml
├── commerce_examples_product_import_ebook.yml
├── commerce_examples_product_import_tshirt.yml
└── commerce_examples_product_variation_import_tshirt.yml
├── composer.json
├── commerce_examples.module
├── src
├── Plugin
│ ├── migrate
│ │ ├── source
│ │ │ ├── Product.php
│ │ │ ├── ProductAttribute.php
│ │ │ └── CSV.php
│ │ └── process
│ │ │ └── Fillerama.php
│ ├── Field
│ │ └── FieldFormatter
│ │ │ └── ColorNameFormatter.php
│ └── Commerce
│ │ └── ShippingMethod
│ │ └── Table.php
├── Resolvers
│ ├── DemoStoreResolver.php
│ ├── UrlQueryPriceResolver.php
│ ├── ProductTypeOrderTypeResolver.php
│ └── RolesOrderTypeResolver.php
├── RevertDemo.php
├── Demo
│ ├── DemoCsv.php
│ ├── MigrationRunner.php
│ └── CSVFileObject.php
├── OrderProcessor
│ └── ApplyTaxAdjustments.php
└── GenerateOrder.php
├── templates
└── commerce-product--full.html.twig
├── README.md
├── commerce_examples.services.yml
├── commerce_examples.install
├── commerce_examples.info.yml
├── tests
└── src
│ └── Kernel
│ ├── DemoInstalledTest.php
│ └── RunMigrationTest.php
└── .travis.yml
/commerce_examples.commerce_adjustment_types.yml:
--------------------------------------------------------------------------------
1 | tax:
2 | label: VAT
3 | has_ui: true
4 | weight: 100
--------------------------------------------------------------------------------
/config/install/commerce_product.commerce_product_attribute.size.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies: { }
4 | id: size
5 | label: Size
6 | elementType: select
7 |
--------------------------------------------------------------------------------
/config/install/commerce_product.commerce_product_attribute.color.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies: { }
4 | id: color
5 | label: Color
6 | elementType: commerce_product_rendered_attribute
7 |
--------------------------------------------------------------------------------
/config/install/commerce_product.commerce_product_variation_type.ebook.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies: { }
4 | id: ebook
5 | label: eBook
6 | orderItemType: default
7 | generateTitle: true
8 | traits: { }
9 |
--------------------------------------------------------------------------------
/config/install/commerce_product.commerce_product_type.ebook.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies: { }
4 | id: ebook
5 | label: eBook
6 | description: ''
7 | variationType: ebook
8 | injectVariationFields: true
9 | traits: { }
10 |
--------------------------------------------------------------------------------
/config/install/commerce_product.commerce_product_type.t_shirt.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies: { }
4 | id: t_shirt
5 | label: T-Shirt
6 | description: ''
7 | variationType: t_shirt
8 | injectVariationFields: true
9 | traits: { }
10 |
--------------------------------------------------------------------------------
/config/install/commerce_product.commerce_product_variation_type.t_shirt.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies: { }
4 | id: t_shirt
5 | label: T-Shirt
6 | orderItemType: default
7 | generateTitle: true
8 | traits:
9 | - purchasable_entity_shippable
10 |
--------------------------------------------------------------------------------
/config/install/commerce_order.commerce_order_type.digital.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies: { }
4 | label: Digital
5 | id: digital
6 | workflow: order_default
7 | traits: { }
8 | refresh_mode: always
9 | refresh_frequency: 30
10 | sendReceipt: true
11 | receiptBcc: ''
12 |
--------------------------------------------------------------------------------
/config/install/commerce_order.commerce_order_type.b2b.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies: { }
4 | label: 'Business to Business'
5 | id: b2b
6 | workflow: order_default
7 | traits: { }
8 | refresh_mode: always
9 | refresh_frequency: 30
10 | sendReceipt: true
11 | receiptBcc: ''
12 |
--------------------------------------------------------------------------------
/data/demo_ebooks.csv:
--------------------------------------------------------------------------------
1 | Name,SKU,Price,Description
2 | Drupal 8 Development Cookbook,AAABBCCCDDD,49.00,One of first Drupal 8 books.
3 | Learning Drupal Commerce,EEFFGGHHII,15.00,"Learn how to Drupal Commerce, the right way."
4 | "Bojan, the King of Pancevo",LKDIODLKD,100.00,Learn about King Bojan of Pancevo
5 |
--------------------------------------------------------------------------------
/config/install/commerce_payment.commerce_payment_gateway.example_on_site.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | module:
5 | - commerce_payment_example
6 | id: example_on_site
7 | label: 'Example On-site'
8 | weight: null
9 | plugin: example_onsite
10 | configuration:
11 | api_key: fsdfdsfsdsdf
12 | mode: test
13 | payment_method_types:
14 | - credit_card
15 |
--------------------------------------------------------------------------------
/config/install/field.storage.commerce_product_variation.weight.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | module:
5 | - commerce_product
6 | - physical
7 | id: commerce_product_variation.weight
8 | field_name: weight
9 | entity_type: commerce_product_variation
10 | type: physical_measurement
11 | settings:
12 | measurement_type: weight
13 | module: physical
14 | locked: true
15 | cardinality: 1
16 | translatable: false
17 | indexes: { }
18 | persist_with_no_fields: false
19 | custom_storage: false
20 |
--------------------------------------------------------------------------------
/migrations/commerce_examples_product_attribute_size.yml:
--------------------------------------------------------------------------------
1 | id: commerce_examples_product_attribute_size
2 | status: true
3 | migration_tags:
4 | - commerce_examples
5 | source:
6 | plugin: commerce_examples_csv_attribute_values
7 | path: data/demo_t_shirts.csv
8 | header_row_count: 1
9 | keys:
10 | - Size
11 | process:
12 | name: Size
13 | attribute:
14 | plugin: default_value
15 | default_value: size
16 | destination:
17 | plugin: 'entity:commerce_product_attribute_value'
18 | migration_dependencies: { }
19 |
--------------------------------------------------------------------------------
/migrations/commerce_examples_product_attribute_color.yml:
--------------------------------------------------------------------------------
1 | id: commerce_examples_product_attribute_color
2 | status: true
3 | migration_tags:
4 | - commerce_examples
5 | source:
6 | plugin: commerce_examples_csv_attribute_values
7 | path: data/demo_t_shirts.csv
8 | header_row_count: 1
9 | keys:
10 | - Color
11 | process:
12 | name: Color
13 | attribute:
14 | plugin: default_value
15 | default_value: color
16 | destination:
17 | plugin: 'entity:commerce_product_attribute_value'
18 | migration_dependencies: { }
19 |
--------------------------------------------------------------------------------
/config/install/field.storage.commerce_product_variation.attribute_color.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | module:
5 | - commerce_product
6 | id: commerce_product_variation.attribute_color
7 | field_name: attribute_color
8 | entity_type: commerce_product_variation
9 | type: entity_reference
10 | settings:
11 | target_type: commerce_product_attribute_value
12 | module: core
13 | locked: false
14 | cardinality: 1
15 | translatable: false
16 | indexes: { }
17 | persist_with_no_fields: false
18 | custom_storage: false
19 |
--------------------------------------------------------------------------------
/config/install/field.storage.commerce_product_variation.attribute_size.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | module:
5 | - commerce_product
6 | id: commerce_product_variation.attribute_size
7 | field_name: attribute_size
8 | entity_type: commerce_product_variation
9 | type: entity_reference
10 | settings:
11 | target_type: commerce_product_attribute_value
12 | module: core
13 | locked: false
14 | cardinality: 1
15 | translatable: false
16 | indexes: { }
17 | persist_with_no_fields: false
18 | custom_storage: false
19 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product.ebook.body.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_type.ebook
6 | - field.storage.commerce_product.body
7 | module:
8 | - text
9 | id: commerce_product.ebook.body
10 | field_name: body
11 | entity_type: commerce_product
12 | bundle: ebook
13 | label: Body
14 | description: ''
15 | required: false
16 | translatable: true
17 | default_value: { }
18 | default_value_callback: ''
19 | settings:
20 | display_summary: false
21 | field_type: text_with_summary
22 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product.t_shirt.body.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_type.t_shirt
6 | - field.storage.commerce_product.body
7 | module:
8 | - text
9 | id: commerce_product.t_shirt.body
10 | field_name: body
11 | entity_type: commerce_product
12 | bundle: t_shirt
13 | label: Body
14 | description: ''
15 | required: false
16 | translatable: true
17 | default_value: { }
18 | default_value_callback: ''
19 | settings:
20 | display_summary: false
21 | field_type: text_with_summary
22 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product.ebook.stores.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_type.ebook
6 | - field.storage.commerce_product.stores
7 | id: commerce_product.ebook.stores
8 | field_name: stores
9 | entity_type: commerce_product
10 | bundle: ebook
11 | label: Stores
12 | description: ''
13 | required: true
14 | translatable: false
15 | default_value: { }
16 | default_value_callback: ''
17 | settings:
18 | handler: 'default:commerce_store'
19 | handler_settings: { }
20 | field_type: entity_reference
21 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product.t_shirt.stores.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_type.t_shirt
6 | - field.storage.commerce_product.stores
7 | id: commerce_product.t_shirt.stores
8 | field_name: stores
9 | entity_type: commerce_product
10 | bundle: t_shirt
11 | label: Stores
12 | description: ''
13 | required: true
14 | translatable: false
15 | default_value: { }
16 | default_value_callback: ''
17 | settings:
18 | handler: 'default:commerce_store'
19 | handler_settings: { }
20 | field_type: entity_reference
21 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_order.digital.order_items.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_order.commerce_order_type.digital
6 | - field.storage.commerce_order.order_items
7 | id: commerce_order.digital.order_items
8 | field_name: order_items
9 | entity_type: commerce_order
10 | bundle: digital
11 | label: 'Order items'
12 | description: ''
13 | required: true
14 | translatable: false
15 | default_value: { }
16 | default_value_callback: null
17 | settings:
18 | handler: 'default:commerce_order_item'
19 | handler_settings: { }
20 | field_type: entity_reference
21 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product_variation.t_shirt.weight.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_variation_type.t_shirt
6 | - field.storage.commerce_product_variation.weight
7 | module:
8 | - physical
9 | id: commerce_product_variation.t_shirt.weight
10 | field_name: weight
11 | entity_type: commerce_product_variation
12 | bundle: t_shirt
13 | label: Weight
14 | description: ''
15 | required: true
16 | translatable: false
17 | default_value: { }
18 | default_value_callback: null
19 | settings: { }
20 | field_type: physical_measurement
21 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "drupal/commerce_examples",
3 | "type": "drupal-module",
4 | "description": "Commerce demo stuff",
5 | "keywords": ["Drupal"],
6 | "license": "GPL-2.0+",
7 | "homepage": "https://www.drupal.org/project/commerce_examples",
8 | "minimum-stability": "dev",
9 | "support": {
10 | "issues": "http://drupal.org/project/issues/commerce_examples",
11 | "source": "http://cgit.drupalcode.org/commerce_examples"
12 | },
13 | "require": {
14 | "drupal/commerce": "^2",
15 | "drupal/commerce_shipping": "^2"
16 | },
17 | "require-dev": {
18 | "drupal/config_devel": "~1"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/migrations/commerce_examples_product_variation_import_ebook.yml:
--------------------------------------------------------------------------------
1 | id: commerce_examples_product_variation_import_ebook
2 | status: true
3 | migration_tags:
4 | - commerce_examples
5 | source:
6 | plugin: csv
7 | path: data/demo_ebooks.csv
8 | header_row_count: 1
9 | keys:
10 | - SKU
11 | process:
12 | title:
13 | plugin: default_value
14 | default_value: null
15 | sku: SKU
16 | type:
17 | plugin: default_value
18 | default_value: ebook
19 | price/number: Price
20 | price/currency_code:
21 | plugin: default_value
22 | default_value: USD
23 | destination:
24 | plugin: 'entity:commerce_product_variation'
25 | migration_dependencies: { }
26 |
--------------------------------------------------------------------------------
/config/install/core.entity_view_display.commerce_product_attribute_value.color.default.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_attribute.color
6 | - field.field.commerce_product_attribute_value.color.field_swatch
7 | module:
8 | - commerce_examples
9 | id: commerce_product_attribute_value.color.default
10 | targetEntityType: commerce_product_attribute_value
11 | bundle: color
12 | mode: default
13 | content:
14 | name:
15 | label: hidden
16 | type: commerce_examples_color_name
17 | weight: -5
18 | region: content
19 | settings: { }
20 | third_party_settings: { }
21 | hidden:
22 | field_swatch: true
23 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product.ebook.variations.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_type.ebook
6 | - commerce_product.commerce_product_variation_type.ebook
7 | - field.storage.commerce_product.variations
8 | id: commerce_product.ebook.variations
9 | field_name: variations
10 | entity_type: commerce_product
11 | bundle: ebook
12 | label: Variations
13 | description: ''
14 | required: true
15 | translatable: false
16 | default_value: { }
17 | default_value_callback: ''
18 | settings:
19 | handler: 'default:commerce_product_variation'
20 | handler_settings:
21 | target_bundles:
22 | - ebook
23 | field_type: entity_reference
24 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product.t_shirt.variations.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_type.t_shirt
6 | - commerce_product.commerce_product_variation_type.t_shirt
7 | - field.storage.commerce_product.variations
8 | id: commerce_product.t_shirt.variations
9 | field_name: variations
10 | entity_type: commerce_product
11 | bundle: t_shirt
12 | label: Variations
13 | description: ''
14 | required: true
15 | translatable: false
16 | default_value: { }
17 | default_value_callback: ''
18 | settings:
19 | handler: 'default:commerce_product_variation'
20 | handler_settings:
21 | target_bundles:
22 | - t_shirt
23 | field_type: entity_reference
24 |
--------------------------------------------------------------------------------
/config/install/field.storage.commerce_product_attribute_value.field_swatch.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | module:
5 | - commerce_product
6 | - file
7 | - image
8 | id: commerce_product_attribute_value.field_swatch
9 | field_name: field_swatch
10 | entity_type: commerce_product_attribute_value
11 | type: image
12 | settings:
13 | uri_scheme: public
14 | default_image:
15 | uuid: ''
16 | alt: ''
17 | title: ''
18 | width: null
19 | height: null
20 | target_type: file
21 | display_field: false
22 | display_default: false
23 | module: image
24 | locked: false
25 | cardinality: 1
26 | translatable: true
27 | indexes: { }
28 | persist_with_no_fields: false
29 | custom_storage: false
30 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product_variation.t_shirt.attribute_size.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_attribute.size
6 | - commerce_product.commerce_product_variation_type.t_shirt
7 | - field.storage.commerce_product_variation.attribute_size
8 | id: commerce_product_variation.t_shirt.attribute_size
9 | field_name: attribute_size
10 | entity_type: commerce_product_variation
11 | bundle: t_shirt
12 | label: Size
13 | description: ''
14 | required: true
15 | translatable: false
16 | default_value: { }
17 | default_value_callback: ''
18 | settings:
19 | handler: 'default:commerce_product_attribute_value'
20 | handler_settings:
21 | target_bundles:
22 | - size
23 | field_type: entity_reference
24 |
--------------------------------------------------------------------------------
/config/install/field.field.commerce_product_variation.t_shirt.attribute_color.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_attribute.color
6 | - commerce_product.commerce_product_variation_type.t_shirt
7 | - field.storage.commerce_product_variation.attribute_color
8 | id: commerce_product_variation.t_shirt.attribute_color
9 | field_name: attribute_color
10 | entity_type: commerce_product_variation
11 | bundle: t_shirt
12 | label: Color
13 | description: ''
14 | required: true
15 | translatable: false
16 | default_value: { }
17 | default_value_callback: ''
18 | settings:
19 | handler: 'default:commerce_product_attribute_value'
20 | handler_settings:
21 | target_bundles:
22 | - color
23 | field_type: entity_reference
24 |
--------------------------------------------------------------------------------
/commerce_examples.module:
--------------------------------------------------------------------------------
1 | [
10 | 'type' => 'sequence',
11 | 'label' => 'Extra keys',
12 | 'sequence' => [
13 | 'type' => 'string',
14 | 'label' => 'Key',
15 | ],
16 | ],
17 | ];
18 | }
19 | }
20 |
21 | /**
22 | * Implements hook_theme().
23 | */
24 | function commerce_examples_theme($existing, $type, $theme, $path) {
25 | return [
26 | 'commerce_product__full' => [
27 | 'render element' => 'elements',
28 | 'base hook' => 'commerce_product',
29 | ],
30 | ];
31 | }
32 |
--------------------------------------------------------------------------------
/config/install/core.entity_view_display.commerce_product.ebook.default.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_type.ebook
6 | - field.field.commerce_product.ebook.body
7 | - field.field.commerce_product.ebook.stores
8 | - field.field.commerce_product.ebook.variations
9 | module:
10 | - commerce_product
11 | - text
12 | id: commerce_product.ebook.default
13 | targetEntityType: commerce_product
14 | bundle: ebook
15 | mode: default
16 | content:
17 | body:
18 | label: hidden
19 | type: text_default
20 | weight: -4
21 | settings: { }
22 | third_party_settings: { }
23 | region: content
24 | variations:
25 | type: commerce_add_to_cart
26 | weight: 0
27 | label: above
28 | settings:
29 | combine: true
30 | third_party_settings: { }
31 | region: content
32 | hidden:
33 | created: true
34 | stores: true
35 | uid: true
36 |
--------------------------------------------------------------------------------
/migrations/commerce_examples_product_import_ebook.yml:
--------------------------------------------------------------------------------
1 | id: commerce_examples_product_import_ebook
2 | status: true
3 | migration_tags:
4 | - commerce_examples
5 | source:
6 | plugin: commerce_examples_product_csv
7 | path: data/demo_ebooks.csv
8 | file_class: Drupal\commerce_examples\Demo\DemoCsv
9 | header_row_count: 1
10 | keys:
11 | - Name
12 | process:
13 | title: Name
14 | type:
15 | plugin: default_value
16 | default_value: ebook
17 | stores:
18 | plugin: default_value
19 | default_value:
20 | - 1
21 | variations/target_id:
22 | -
23 | plugin: migration
24 | migration: commerce_examples_product_variation_import_ebook
25 | source: product_variations
26 | -
27 | plugin: skip_on_empty
28 | method: row
29 | body:
30 | plugin: fillerama
31 | destination:
32 | plugin: 'entity:commerce_product'
33 | migration_dependencies:
34 | required:
35 | - commerce_examples_product_variation_import_ebook
36 |
--------------------------------------------------------------------------------
/src/Plugin/migrate/source/Product.php:
--------------------------------------------------------------------------------
1 | getSourceProperty('SKU'), 0, 9);
27 |
28 | $query = \Drupal::entityQuery('commerce_product_variation')
29 | ->condition('sku', $sku_prefix, 'STARTS_WITH');
30 |
31 | $values = $query->execute();
32 |
33 | foreach ($values as $value) {
34 | $targets[] = ['target_id' => $value];
35 | }
36 |
37 | $row->setDestinationProperty('variations', $targets);
38 | $row->rehash();
39 | return TRUE;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/config/install/core.entity_view_display.commerce_product.t_shirt.default.yml:
--------------------------------------------------------------------------------
1 | langcode: en
2 | status: true
3 | dependencies:
4 | config:
5 | - commerce_product.commerce_product_type.t_shirt
6 | - field.field.commerce_product.t_shirt.body
7 | - field.field.commerce_product.t_shirt.stores
8 | - field.field.commerce_product.t_shirt.variations
9 | module:
10 | - commerce_product
11 | - text
12 | id: commerce_product.t_shirt.default
13 | targetEntityType: commerce_product
14 | bundle: t_shirt
15 | mode: default
16 | content:
17 | body:
18 | label: hidden
19 | type: text_default
20 | weight: -4
21 | settings: { }
22 | third_party_settings: { }
23 | region: content
24 | variations:
25 | type: commerce_add_to_cart
26 | weight: 0
27 | label: hidden
28 | settings:
29 | show_quantity: false
30 | default_quantity: '1'
31 | combine: true
32 | third_party_settings: { }
33 | region: content
34 | hidden:
35 | created: true
36 | stores: true
37 | uid: true
38 |
--------------------------------------------------------------------------------
/templates/commerce-product--full.html.twig:
--------------------------------------------------------------------------------
1 | {#
2 | /**
3 | * @file
4 | *
5 | * Default product template.
6 | *
7 | * Available variables:
8 | * - attributes: HTML attributes for the wrapper.
9 | * - product: The rendered product fields.
10 | * Use 'product' to print them all, or print a subset such as
11 | * 'product.title'. Use the following code to exclude the
12 | * printing of a given field:
13 | * @code
14 | * {{ product|without('title') }}
15 | * @endcode
16 | * - product_entity: The product entity.
17 | * - product_url: The product URL.
18 | *
19 | * @ingroup themeable
20 | */
21 | #}
22 |
' . implode(' ', $sentences) . '
'; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/Plugin/Commerce/ShippingMethod/Table.php: -------------------------------------------------------------------------------- 1 | services['default'] = new ShippingService('default', 'Ground shipping'); 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | public function defaultConfiguration() { 43 | return [ 44 | 'services' => ['default'], 45 | ] + parent::defaultConfiguration(); 46 | } 47 | 48 | /** 49 | * {@inheritdoc} 50 | */ 51 | public function calculateRates(ShipmentInterface $shipment) { 52 | // Rate IDs aren't used in a flat rate scenario because there's always a 53 | // single rate per plugin, and there's no support for purchasing rates. 54 | $rate_id = 0; 55 | 56 | // Table rate starts at $5.00. 57 | $rate_amount = '5.00'; 58 | 59 | $order_total_number = $shipment->getOrder()->getTotalPrice()->getNumber(); 60 | 61 | if ($order_total_number > '100') { 62 | $rate_amount = '12.00'; 63 | } 64 | elseif ($order_total_number > '50') { 65 | $rate_amount = '9.00'; 66 | } 67 | elseif ($order_total_number > '25') { 68 | $rate_amount = '7.25'; 69 | } 70 | 71 | $amount = new Price($rate_amount, $shipment->getOrder()->getTotalPrice()->getCurrencyCode()); 72 | $rates = []; 73 | $rates[] = new ShippingRate($rate_id, $this->services['default'], $amount); 74 | 75 | return $rates; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /commerce_examples.info.yml: -------------------------------------------------------------------------------- 1 | name: Commerce Examples 2 | type: module 3 | description: Commerce example stuff 4 | core: 8.x 5 | package: Custom 6 | dependencies: 7 | - file 8 | - image 9 | - commerce_store 10 | - commerce_product 11 | - commerce_payment_example 12 | - migrate 13 | - commerce_shipping 14 | 15 | config_devel: 16 | install: 17 | - commerce_order.commerce_order_type.b2b 18 | - commerce_order.commerce_order_type.digital 19 | - commerce_payment.commerce_payment_gateway.example_on_site 20 | - commerce_product.commerce_product_attribute.color 21 | - commerce_product.commerce_product_attribute.size 22 | - commerce_product.commerce_product_type.ebook 23 | - commerce_product.commerce_product_type.t_shirt 24 | - commerce_product.commerce_product_variation_type.ebook 25 | - commerce_product.commerce_product_variation_type.t_shirt 26 | - core.entity_form_display.commerce_order.digital.default 27 | - core.entity_form_display.commerce_product.t_shirt.default 28 | - core.entity_form_display.commerce_product_variation.t_shirt.default 29 | - core.entity_view_display.commerce_product.ebook.default 30 | - core.entity_view_display.commerce_product.t_shirt.default 31 | - core.entity_view_display.commerce_product_attribute_value.color.default 32 | - core.entity_view_display.commerce_product_variation.ebook.default 33 | - core.entity_view_display.commerce_product_variation.t_shirt.default 34 | - field.field.commerce_order.digital.order_items 35 | - field.field.commerce_product.ebook.body 36 | - field.field.commerce_product.ebook.stores 37 | - field.field.commerce_product.ebook.variations 38 | - field.field.commerce_product.t_shirt.body 39 | - field.field.commerce_product.t_shirt.stores 40 | - field.field.commerce_product.t_shirt.variations 41 | - field.field.commerce_product_attribute_value.color.field_swatch 42 | - field.field.commerce_product_variation.t_shirt.attribute_color 43 | - field.field.commerce_product_variation.t_shirt.attribute_size 44 | - field.field.commerce_product_variation.t_shirt.weight 45 | - field.storage.commerce_product_attribute_value.field_swatch 46 | - field.storage.commerce_product_variation.attribute_color 47 | - field.storage.commerce_product_variation.attribute_size 48 | - field.storage.commerce_product_variation.weight 49 | - migrate_plus.migration.commerce_examples_product_attribute_color 50 | - migrate_plus.migration.commerce_examples_product_attribute_size 51 | - migrate_plus.migration.commerce_examples_product_import_ebook 52 | - migrate_plus.migration.commerce_examples_product_import_tshirt 53 | - migrate_plus.migration.commerce_examples_product_variation_import_ebook 54 | - migrate_plus.migration.commerce_examples_product_variation_import_tshirt 55 | - migrate_plus.migration_group.commerce_examples_ebook 56 | - migrate_plus.migration_group.commerce_examples_tshirt 57 | - field.field.commerce_order.default.shipments 58 | - field.storage.commerce_order.shipments 59 | - user.role.store_admin 60 | -------------------------------------------------------------------------------- /src/Demo/CSVFileObject.php: -------------------------------------------------------------------------------- 1 | setFlags(CSVFileObject::READ_CSV | CSVFileObject::READ_AHEAD | CSVFileObject::DROP_NEW_LINE | CSVFileObject::SKIP_EMPTY); 40 | } 41 | 42 | /** 43 | * {@inheritdoc} 44 | */ 45 | public function rewind() { 46 | $this->seek($this->getHeaderRowCount()); 47 | } 48 | 49 | /** 50 | * {@inheritdoc} 51 | */ 52 | public function current() { 53 | $row = parent::current(); 54 | 55 | if ($row && !empty($this->columnNames)) { 56 | // Only use columns specified in the defined CSV columns. 57 | $row = array_intersect_key($row, $this->columnNames); 58 | // Set meaningful keys for the columns mentioned in $this->csvColumns. 59 | foreach ($this->columnNames as $key => $value) { 60 | // Copy value to more descriptive key and unset original. 61 | $value = key($value); 62 | $row[$value] = isset($row[$key]) ? $row[$key] : NULL; 63 | unset($row[$key]); 64 | } 65 | } 66 | 67 | return $row; 68 | } 69 | 70 | /** 71 | * Return a count of all available source records. 72 | */ 73 | public function count() { 74 | return iterator_count($this); 75 | } 76 | 77 | /** 78 | * Number of header rows. 79 | * 80 | * @return int 81 | * Get the number of header rows, zero if no header row. 82 | */ 83 | public function getHeaderRowCount() { 84 | return $this->headerRowCount; 85 | } 86 | 87 | /** 88 | * Number of header rows. 89 | * 90 | * @param int $header_row_count 91 | * Set the number of header rows, zero if no header row. 92 | */ 93 | public function setHeaderRowCount($header_row_count) { 94 | $this->headerRowCount = $header_row_count; 95 | } 96 | 97 | /** 98 | * CSV column names. 99 | * 100 | * @return array 101 | * Get CSV column names. 102 | */ 103 | public function getColumnNames() { 104 | return $this->columnNames; 105 | } 106 | 107 | /** 108 | * CSV column names. 109 | * 110 | * @param array $column_names 111 | * Set CSV column names. 112 | */ 113 | public function setColumnNames(array $column_names) { 114 | $this->columnNames = $column_names; 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /tests/src/Kernel/DemoInstalledTest.php: -------------------------------------------------------------------------------- 1 | installSchema('system', 'router'); 39 | $this->installEntitySchema('user'); 40 | $this->installEntitySchema('commerce_store'); 41 | $this->installEntitySchema('commerce_product_attribute'); 42 | $this->installEntitySchema('commerce_product_attribute_value'); 43 | $this->installEntitySchema('commerce_product_variation'); 44 | $this->installEntitySchema('commerce_product_variation_type'); 45 | $this->installEntitySchema('commerce_product'); 46 | $this->installEntitySchema('commerce_product_type'); 47 | $this->installEntitySchema('commerce_shipment'); 48 | $this->installEntitySchema('commerce_shipment_type'); 49 | $this->installEntitySchema('commerce_shipping_method'); 50 | $this->installConfig(static::$modules); 51 | } 52 | 53 | /** 54 | * Test product and variation type imported. 55 | */ 56 | public function testProductType() { 57 | $product_type = ProductType::load('t_shirt'); 58 | $this->assertNotNull($product_type); 59 | $product_variation_type = ProductVariationType::load('t_shirt'); 60 | $this->assertNotNull($product_variation_type); 61 | } 62 | 63 | /** 64 | * Tests around attributes. 65 | */ 66 | public function testAttributesImported() { 67 | $color = ProductAttribute::load('color'); 68 | $this->assertNotNull($color); 69 | $size = ProductAttribute::load('size'); 70 | $this->assertNotNull($size); 71 | } 72 | 73 | /** 74 | * Tests that the demo store is installed. 75 | */ 76 | public function testStoreInstalled() { 77 | module_load_install('commerce_examples'); 78 | commerce_examples_install(); 79 | 80 | /** @var \Drupal\commerce_store\StoreStorageInterface $store_storage */ 81 | $store_storage = $this->container->get('entity_type.manager')->getStorage('commerce_store'); 82 | 83 | $demo_store = $store_storage->loadDefault(); 84 | $this->assertEquals('Demo store', $demo_store->label()); 85 | $this->assertEquals('admin@example.com', $demo_store->getEmail()); 86 | $this->assertEquals('USD', $demo_store->getDefaultCurrencyCode()); 87 | 88 | $demo_address = $demo_store->getAddress(); 89 | $this->assertEquals('US', $demo_address->getCountryCode()); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /tests/src/Kernel/RunMigrationTest.php: -------------------------------------------------------------------------------- 1 | installSchema('system', 'router'); 37 | $this->installEntitySchema('user'); 38 | $this->installEntitySchema('commerce_store'); 39 | $this->installEntitySchema('commerce_product_attribute'); 40 | $this->installEntitySchema('commerce_product_attribute_value'); 41 | $this->installEntitySchema('commerce_product_variation'); 42 | $this->installEntitySchema('commerce_product_variation_type'); 43 | $this->installEntitySchema('commerce_product'); 44 | $this->installEntitySchema('commerce_product_type'); 45 | $this->installConfig(static::$modules); 46 | 47 | $this->container->get('commerce_examples.migration_runner')->run(); 48 | } 49 | 50 | /** 51 | * Tests around attributes. 52 | */ 53 | public function testAttributesImported() { 54 | $color = ProductAttribute::load('color'); 55 | /** @var \Drupal\commerce_product\Entity\ProductAttributeValueInterface[] $color_values */ 56 | $color_values = $color->getValues(); 57 | $this->assertNotEmpty($color_values); 58 | $this->assertEquals(4, count($color_values)); 59 | 60 | $size = ProductAttribute::load('size'); 61 | $size_values = $size->getValues(); 62 | $this->assertNotEmpty($size_values); 63 | $this->assertEquals(3, count($size_values)); 64 | } 65 | 66 | /** 67 | * Tests that the products got imported. 68 | */ 69 | public function testProductsImported() { 70 | $products = Product::loadMultiple(); 71 | $this->assertNotEmpty($products); 72 | $this->assertEquals(5, count($products)); 73 | 74 | /** @var \Drupal\commerce_product\Entity\ProductInterface $product */ 75 | foreach ($products as $product) { 76 | switch ($product->label()) { 77 | case 'Commerce Guys Hoodie': 78 | $this->assertEquals(12, count($product->getVariations())); 79 | $default_variation = $product->getDefaultVariation(); 80 | $this->assertEquals(10, $default_variation->get('weight')->number); 81 | $this->assertEquals(' oz', $default_variation->get('weight')->unit); 82 | break; 83 | 84 | case 'Drupal Commerce Cart Shirt': 85 | $this->assertEquals(12, count($product->getVariations())); 86 | $default_variation = $product->getDefaultVariation(); 87 | $this->assertEquals(7, $default_variation->get('weight')->number); 88 | $this->assertEquals(' oz', $default_variation->get('weight')->unit); 89 | break; 90 | } 91 | } 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # @file 2 | # .travis.yml - Drupal for Travis CI Integration 3 | # 4 | # Template provided by https://github.com/LionsAd/drupal_ti. 5 | 6 | language: php 7 | 8 | sudo: false 9 | 10 | php: 11 | - 7 12 | - 5.6 13 | - 5.5 14 | 15 | branches: 16 | except: 17 | - "7.x-1.x" 18 | 19 | matrix: 20 | fast_finish: true 21 | 22 | env: 23 | global: 24 | - PHANTOMJS2_VERSION="2.0.0" 25 | # add composer's global bin directory to the path 26 | # see: https://github.com/drush-ops/drush#install---composer 27 | - PATH="$PATH:$HOME/.composer/vendor/bin" 28 | 29 | # Configuration variables. 30 | - DRUPAL_TI_MODULE_NAME="commerce_examples" 31 | - DRUPAL_TI_SIMPLETEST_GROUP="commerce_examples" 32 | 33 | # Define runners and environment vars to include before and after the 34 | # main runners / environment vars. 35 | #- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before" 36 | #- DRUPAL_TI_SCRIPT_DIR_AFTER="./drupal_ti/after" 37 | 38 | # The environment to use, supported are: drupal-7, drupal-8 39 | - DRUPAL_TI_ENVIRONMENT="drupal-8" 40 | - DRUPAL_TI_CORE_BRANCH="8.3.x" 41 | 42 | # Drupal specific variables. 43 | - DRUPAL_TI_DB="drupal_travis_db" 44 | - DRUPAL_TI_DB_URL="mysql://root:@127.0.0.1/drupal_travis_db" 45 | # Note: Do not add a trailing slash here. 46 | - DRUPAL_TI_WEBSERVER_URL="http://127.0.0.1" 47 | - DRUPAL_TI_WEBSERVER_PORT="8080" 48 | 49 | # Simpletest specific commandline arguments, the DRUPAL_TI_SIMPLETEST_GROUP is appended at the end. 50 | - DRUPAL_TI_SIMPLETEST_ARGS="--verbose --color --concurrency 4 --url $DRUPAL_TI_WEBSERVER_URL:$DRUPAL_TI_WEBSERVER_PORT --types Simpletest" 51 | 52 | # === Behat specific variables. 53 | # This is relative to $TRAVIS_BUILD_DIR 54 | - DRUPAL_TI_BEHAT_DIR="./tests/behat" 55 | # These arguments are passed to the bin/behat command. 56 | - DRUPAL_TI_BEHAT_ARGS="" 57 | # Specify the filename of the behat.yml with the $DRUPAL_TI_DRUPAL_DIR variables. 58 | - DRUPAL_TI_BEHAT_YML="behat.yml.dist" 59 | # This is used to setup Xvfb. 60 | - DRUPAL_TI_BEHAT_SCREENSIZE_COLOR="1280x1024x16" 61 | # The version of selenium that should be used. 62 | - DRUPAL_TI_BEHAT_SELENIUM_VERSION="2.44" 63 | # Set DRUPAL_TI_BEHAT_DRIVER to "selenium" to use "firefox" or "chrome" here. 64 | - DRUPAL_TI_BEHAT_DRIVER="phantomjs" 65 | - DRUPAL_TI_BEHAT_BROWSER="firefox" 66 | 67 | # PHPUnit specific commandline arguments. 68 | - DRUPAL_TI_PHPUNIT_ARGS="" 69 | # Specifying the phpunit-core src/ directory is useful when e.g. a vendor/ 70 | # directory is present in the module directory, which phpunit would then 71 | # try to find tests in. This option is relative to $TRAVIS_BUILD_DIR. 72 | #- DRUPAL_TI_PHPUNIT_CORE_SRC_DIRECTORY="./tests/src" 73 | 74 | # Code coverage via coveralls.io 75 | - DRUPAL_TI_COVERAGE="satooshi/php-coveralls:0.6.*" 76 | # This needs to match your .coveralls.yml file. 77 | - DRUPAL_TI_COVERAGE_FILE="build/logs/clover.xml" 78 | 79 | # Debug options 80 | #- DRUPAL_TI_DEBUG="-x -v" 81 | # Set to "all" to output all files, set to e.g. "xvfb selenium" or "selenium", 82 | # etc. to only output those channels. 83 | #- DRUPAL_TI_DEBUG_FILE_OUTPUT="selenium xvfb webserver" 84 | - DRUPAL_TI_MODULES_PATH="modules/contrib" 85 | 86 | matrix: 87 | # [[[ SELECT ANY OR MORE OPTIONS ]]] 88 | #- DRUPAL_TI_RUNNERS="phpunit" 89 | - DRUPAL_TI_RUNNERS="phpunit-core" 90 | #- DRUPAL_TI_RUNNERS="behat" 91 | #- DRUPAL_TI_RUNNERS="phpunit simpletest behat" 92 | 93 | mysql: 94 | database: drupal_travis_db 95 | username: root 96 | encoding: utf8 97 | 98 | before_install: 99 | # Remove xdebug. We aren't generating code coverage, and it slows down Composer. 100 | - phpenv config-rm xdebug.ini || true 101 | - composer global require "hirak/prestissimo:^0.3" 102 | - composer global require "lionsad/drupal_ti:dev-master#396d11d200005eb68491d24170da0a98ae7f51b3" 103 | - composer global require "squizlabs/php_codesniffer:2.*" 104 | - composer global require "drupal/coder:8.2.*" 105 | - phpcs --config-set installed_paths $HOME/.composer/vendor/drupal/coder/coder_sniffer 106 | - drupal-ti before_install 107 | 108 | install: 109 | - drupal-ti install 110 | 111 | before_script: 112 | - drupal-ti before_script 113 | 114 | script: 115 | - phpcs --standard=Drupal src 116 | - phpcs --standard=Drupal tests 117 | - drupal-ti script 118 | 119 | after_script: 120 | - drupal-ti after_script 121 | 122 | notifications: 123 | email: false 124 | -------------------------------------------------------------------------------- /src/Plugin/migrate/source/CSV.php: -------------------------------------------------------------------------------- 1 | configuration['path'])) { 60 | throw new MigrateException('You must declare the "path" to the source CSV file in your source settings.'); 61 | } 62 | 63 | // Key field(s) are required. 64 | if (empty($this->configuration['keys'])) { 65 | throw new MigrateException('You must declare "keys" as a unique array of fields in your source settings.'); 66 | } 67 | 68 | $this->fileClass = empty($configuration['file_class']) ? 'Drupal\commerce_examples\Demo\CSVFileObject' : $configuration['file_class']; 69 | } 70 | 71 | /** 72 | * Return a string representing the source file path. 73 | * 74 | * @return string 75 | * The file path. 76 | */ 77 | public function __toString() { 78 | return $this->configuration['path']; 79 | } 80 | 81 | /** 82 | * {@inheritdoc} 83 | */ 84 | public function initializeIterator() { 85 | // File handler using header-rows-respecting extension of SPLFileObject. 86 | $module_handler = $this->getModuleHandler(); 87 | $migration_info = $this->migration->getPluginDefinition(); 88 | $module = $module_handler->getModule($migration_info['provider']); 89 | $this->file = new $this->fileClass(DRUPAL_ROOT . '/' . $module->getPath() . '/' . $this->configuration['path']); 90 | 91 | // Set basics of CSV behavior based on configuration. 92 | $delimiter = !empty($this->configuration['delimiter']) ? $this->configuration['delimiter'] : ','; 93 | $enclosure = !empty($this->configuration['enclosure']) ? $this->configuration['enclosure'] : '"'; 94 | $escape = !empty($this->configuration['escape']) ? $this->configuration['escape'] : '\\'; 95 | $this->file->setCsvControl($delimiter, $enclosure, $escape); 96 | 97 | // Figure out what CSV column(s) to use. Use either the header row(s) or 98 | // explicitly provided column name(s). 99 | if (!empty($this->configuration['header_row_count'])) { 100 | $this->file->setHeaderRowCount($this->configuration['header_row_count']); 101 | 102 | // Find the last header line. 103 | $this->file->rewind(); 104 | $this->file->seek($this->file->getHeaderRowCount() - 1); 105 | 106 | $row = $this->file->current(); 107 | foreach ($row as $header) { 108 | $header = trim($header); 109 | $column_names[] = [$header => $header]; 110 | } 111 | $this->file->setColumnNames($column_names); 112 | } 113 | // An explicit list of column name(s) will override any header row(s). 114 | if (!empty($this->configuration['column_names'])) { 115 | $this->file->setColumnNames($this->configuration['column_names']); 116 | } 117 | 118 | return $this->file; 119 | } 120 | 121 | /** 122 | * {@inheritdoc} 123 | */ 124 | public function getIds() { 125 | $ids = []; 126 | foreach ($this->configuration['keys'] as $delta => $value) { 127 | if (is_array($value)) { 128 | $ids[$delta] = $value; 129 | } 130 | else { 131 | $ids[$value]['type'] = 'string'; 132 | } 133 | } 134 | return $ids; 135 | } 136 | 137 | /** 138 | * {@inheritdoc} 139 | */ 140 | public function fields() { 141 | $fields = []; 142 | foreach ($this->getIterator()->getColumnNames() as $column) { 143 | $fields[key($column)] = reset($column); 144 | } 145 | 146 | // Any caller-specified fields with the same names as extracted fields will 147 | // override them; any others will be added. 148 | if (!empty($this->configuration['fields'])) { 149 | $fields = $this->configuration['fields'] + $fields; 150 | } 151 | 152 | return $fields; 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/GenerateOrder.php: -------------------------------------------------------------------------------- 1 | entityTypeManager = $entityTypeManager; 54 | $this->variantStorage = $entityTypeManager->getStorage('commerce_product_variation'); 55 | $this->orderItemStorage = $entityTypeManager->getStorage('commerce_order_item'); 56 | $this->orderStorage = $entityTypeManager->getStorage('commerce_order'); 57 | $this->client = $client; 58 | $this->rounder = $rounder; 59 | } 60 | 61 | public function bulkCreate() { 62 | $start = new \DateTime(); 63 | $start->modify('-1 year'); 64 | 65 | $end = new \DateTime(); 66 | $end->modify('today'); 67 | 68 | for ($i = $start; $i <= $end; $i->modify('+1 day')) { 69 | $how_many = rand(3, 15); 70 | for ($x = 0; $x < $how_many; $x++) { 71 | $this->create($i); 72 | print PHP_EOL . $i->format(\DateTime::ISO8601); 73 | } 74 | $event_dispatcher = \Drupal::getContainer()->get('event_dispatcher'); 75 | $event_dispatcher->dispatch( 76 | KernelEvents::TERMINATE, 77 | new PostResponseEvent(\Drupal::getContainer()->get('kernel'), new Request(), new Response()) 78 | ); 79 | } 80 | } 81 | 82 | public function create(\DateTime $when = NULL) { 83 | if (!$when) { 84 | $when = new \DateTime(); 85 | $when->modify('-1 month'); 86 | } 87 | 88 | $person = $this->getRandomUser(); 89 | $address = $this->getRandomAddress(); 90 | 91 | /** @var \Drupal\commerce_order\Entity\OrderInterface $order */ 92 | $order = $this->orderStorage->create([ 93 | 'uid' => 0, 94 | 'type' => 'default', 95 | ]); 96 | $order->setEmail($person['email']); 97 | $order->setPlacedTime($when->getTimestamp()); 98 | $order->setCreatedTime($when->getTimestamp()); 99 | $order->setStore(Store::load(1)); 100 | $order->setIpAddress($this->getRandomIp()); 101 | 102 | $variations = $this->getRandomVariants(); 103 | $order_items = []; 104 | foreach ($variations as $variation) { 105 | $order_item = $this->orderItemStorage->createFromPurchasableEntity($variation); 106 | // Order item total calc happens on save. 107 | $total_price = $order_item->getUnitPrice()->multiply($order_item->getQuantity()); 108 | $order_item->total_price = $this->rounder->round($total_price); 109 | 110 | $order_items[] = $order_item; 111 | } 112 | 113 | $order->setItems($order_items); 114 | $order->recalculateTotalPrice(); 115 | 116 | $profile = Profile::create([ 117 | 'type' => 'customer', 118 | 'address' => [ 119 | 'organization' => '', 120 | 'country_code' => 'US', 121 | 'postal_code' => $address['postal_code'], 122 | 'locality' => $address['locality'], 123 | 'address_line1' => $address['address_line1'], 124 | 'administrative_area' => $address['administrative_area'], 125 | 'given_name' => ucfirst($person['name']['first']), 126 | 'family_name' => ucfirst($person['name']['last']), 127 | ], 128 | 'uid' => 0, 129 | ]); 130 | $profile->save(); 131 | $order->setBillingProfile($profile); 132 | $order->save(); 133 | 134 | $workflow = $order->getState()->getWorkflow(); 135 | $order->getState()->applyTransition($workflow->getTransition('place')); 136 | $order->save(); 137 | } 138 | 139 | /** 140 | * Gets a set of 1-4 random variations. 141 | * 142 | * @return \Drupal\commerce_product\Entity\ProductVariationInterface[] 143 | * The variations. 144 | */ 145 | protected function getRandomVariants() { 146 | $variations = $this->variantStorage->loadByProperties(['type' => 't_shirt']); 147 | 148 | $keys = array_rand($variations, rand(2, 5)); 149 | $demo_variations = []; 150 | foreach ($keys as $key) { 151 | $demo_variations[] = $variations[$key]; 152 | } 153 | 154 | return $demo_variations; 155 | } 156 | 157 | protected function getRandomIp() { 158 | $ips = [ 159 | '75.86.161.54', 160 | '75.26.161.58', 161 | '15.26.161.58', 162 | ]; 163 | 164 | return $ips[array_rand($ips)]; 165 | } 166 | 167 | protected function getRandomUser() { 168 | $person = $this->client->get('https://randomuser.me/api/'); 169 | $person = Json::decode($person->getBody()->getContents()); 170 | return $person['results'][0]; 171 | } 172 | 173 | protected function getRandomAddress() { 174 | $addresses = [ 175 | [ 176 | 'address_line1' => '8502 Pilgrim St.', 177 | 'locality' => 'Mokena', 178 | 'administrative_area' => 'IL', 179 | 'postal_code' => '60448', 180 | ], 181 | [ 182 | 'address_line1' => '7691 East 6th St', 183 | 'locality' => 'Lewiston', 184 | 'administrative_area' => 'ME', 185 | 'postal_code' => '04240', 186 | ], 187 | [ 188 | 'address_line1' => '315 Addison Court ', 189 | 'locality' => 'New Windsor', 190 | 'administrative_area' => 'NY', 191 | 'postal_code' => '12553', 192 | ], 193 | [ 194 | 'address_line1' => '45 Bow Ridge Ave', 195 | 'locality' => 'West Chicago', 196 | 'administrative_area' => 'IL', 197 | 'postal_code' => '60185', 198 | ], 199 | [ 200 | 'address_line1' => '4 Washington Avenue', 201 | 'locality' => 'Commack', 202 | 'administrative_area' => 'NY', 203 | 'postal_code' => '11725', 204 | ], 205 | [ 206 | 'address_line1' => '31 Fairfield Dr', 207 | 'locality' => 'Bonita Springs', 208 | 'administrative_area' => 'FL', 209 | 'postal_code' => '34135', 210 | ], 211 | [ 212 | 'address_line1' => '8757 Homestead St', 213 | 'locality' => 'Port Chester', 214 | 'administrative_area' => 'NY', 215 | 'postal_code' => '10573', 216 | ], 217 | [ 218 | 'address_line1' => '8281 Fawn St.', 219 | 'locality' => 'Strongsville', 220 | 'administrative_area' => 'OH', 221 | 'postal_code' => '44136', 222 | ], 223 | [ 224 | 'address_line1' => '7364 Wild Horse Street', 225 | 'locality' => 'Wake Forest', 226 | 'administrative_area' => 'NC', 227 | 'postal_code' => '27587', 228 | ], 229 | [ 230 | 'address_line1' => '7267 Surrey Ave', 231 | 'locality' => 'Butler', 232 | 'administrative_area' => 'PA', 233 | 'postal_code' => '16001', 234 | ], 235 | ]; 236 | 237 | return $addresses[array_rand($addresses)]; 238 | } 239 | 240 | } 241 | -------------------------------------------------------------------------------- /data/fillerama.json: -------------------------------------------------------------------------------- 1 | {"db":[{"source":"Luke Skywalker","quote":"You don't believe in the Force, do you?"},{"source":"Leia","quote":"I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--"},{"source":"Darth Vader","quote":"Obi-Wan is here. The Force is with him."},{"source":"Darth Vader","quote":"He is here."},{"source":"Han Solo","quote":"I'm trying not to, kid."},{"source":"Darth Vader","quote":"Don't underestimate the Force."},{"source":"Luke Skywalker","quote":"I care. So, what do you think of her, Han?"},{"source":"Luke Skywalker","quote":"I care. So, what do you think of her, Han?"},{"source":"Han Solo","quote":"Hokey religions and ancient weapons are no match for a good blaster at your side, kid."},{"source":"Darth Vader","quote":"Don't be too proud of this technological terror you've constructed. The ability to destroy a planet is insignificant next to the power of the Force."},{"source":"Luke Skywalker","quote":"You mean it controls your actions?"},{"source":"Ben Kenobi","quote":"Remember, a Jedi can feel the Force flowing through him."},{"source":"Leia","quote":"I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--"},{"source":"Darth Vader","quote":"She must have hidden the plans in the escape pod. Send a detachment down to retrieve them, and see to it personally, Commander. There'll be no one to stop us this time!"},{"source":"Han Solo","quote":"Still, she's got a lot of spirit. I don't know, what do you think?"},{"source":"Luke Skywalker","quote":"Look, I can take you as far as Anchorhead. You can get a transport there to Mos Eisley or wherever you're going."},{"source":"Leia","quote":"The more you tighten your grip, Tarkin, the more star systems will slip through your fingers."},{"source":"Han Solo","quote":"Hey, Luke! May the Force be with you."},{"source":"Han Solo","quote":"Look, I ain't in this for your revolution, and I'm not in it for you, Princess. I expect to be well paid. I'm in it for the money."},{"source":"Ben Kenobi","quote":"I suggest you try it again, Luke. This time, let go your conscious self and act on instinct."},{"source":"Darth Vader","quote":"He is here."},{"source":"Darth Vader","quote":"He is here."},{"source":"Leia","quote":"What?!"},{"source":"Darth Vader","quote":"What!?"},{"source":"Darth Vader","quote":"Don't underestimate the Force."},{"source":"Han Solo","quote":"Ye-ha!"},{"source":"Leia","quote":"I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--"},{"source":"Leia","quote":"I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--"},{"source":"Darth Vader","quote":"What!?"},{"source":"Luke Skywalker","quote":"But with the blast shield down, I can't even see! How am I supposed to fight?"},{"source":"Luke Skywalker","quote":"Oh God, my uncle. How am I ever gonna explain this?"},{"source":"Luke Skywalker","quote":"But with the blast shield down, I can't even see! How am I supposed to fight?"},{"source":"Luke Skywalker","quote":"You don't believe in the Force, do you?"},{"source":"Ben Kenobi","quote":"Remember, a Jedi can feel the Force flowing through him."},{"source":"Ben Kenobi","quote":"Partially, but it also obeys your commands."},{"source":"Leia","quote":"The more you tighten your grip, Tarkin, the more star systems will slip through your fingers."},{"source":"Luke Skywalker","quote":"Red Five standing by."},{"source":"Luke Skywalker","quote":"But with the blast shield down, I can't even see! How am I supposed to fight?"},{"source":"Ben Kenobi","quote":"I need your help, Luke. She needs your help. I'm getting too old for this sort of thing."},{"source":"Darth Vader","quote":"A tremor in the Force. The last time I felt it was in the presence of my old master."},{"source":"Ben Kenobi","quote":"Remember, a Jedi can feel the Force flowing through him."},{"source":"Ben Kenobi","quote":"In my experience, there is no such thing as luck."},{"source":"Darth Vader","quote":"You are a part of the Rebel Alliance and a traitor! Take her away!"},{"source":"Han Solo","quote":"Ye-ha!"},{"source":"Han Solo","quote":"What good is a reward if you ain't around to use it? Besides, attacking that battle station ain't my idea of courage. It's more like…suicide."},{"source":"Darth Vader","quote":"The plans you refer to will soon be back in our hands."},{"source":"Darth Vader","quote":"A tremor in the Force. The last time I felt it was in the presence of my old master."},{"source":"Luke Skywalker","quote":"Oh God, my uncle. How am I ever gonna explain this?"},{"source":"Darth Vader","quote":"Don't act so surprised, Your Highness. You weren't on any mercy mission this time. Several transmissions were beamed to this ship by Rebel spies. I want to know what happened to the plans they sent you."},{"source":"Darth Vader","quote":"Don't be too proud of this technological terror you've constructed. The ability to destroy a planet is insignificant next to the power of the Force."},{"source":"Luke Skywalker","quote":"I can't get involved! I've got work to do! It's not that I like the Empire, I hate it, but there's nothing I can do about it right now. It's such a long way from here."},{"source":"Darth Vader","quote":"Obi-Wan is here. The Force is with him."},{"source":"Darth Vader","quote":"Don't be too proud of this technological terror you've constructed. The ability to destroy a planet is insignificant next to the power of the Force."},{"source":"Luke Skywalker","quote":"You mean it controls your actions?"},{"source":"Ben Kenobi","quote":"In my experience, there is no such thing as luck."},{"source":"Darth Vader","quote":"The Force is strong with this one. I have you now."},{"source":"Ben Kenobi","quote":"Partially, but it also obeys your commands."},{"source":"Luke Skywalker","quote":"I want to come with you to Alderaan. There's nothing for me here now. I want to learn the ways of the Force and be a Jedi, like my father before me."},{"source":"Darth Vader","quote":"You are a part of the Rebel Alliance and a traitor! Take her away!"},{"source":"Darth Vader","quote":"The Force is strong with this one. I have you now."},{"source":"Darth Vader","quote":"She must have hidden the plans in the escape pod. Send a detachment down to retrieve them, and see to it personally, Commander. There'll be no one to stop us this time!"},{"source":"Luke Skywalker","quote":"You don't believe in the Force, do you?"},{"source":"Ben Kenobi","quote":"Partially, but it also obeys your commands."},{"source":"Darth Vader","quote":"Don't be too proud of this technological terror you've constructed. The ability to destroy a planet is insignificant next to the power of the Force."},{"source":"Darth Vader","quote":"Don't be too proud of this technological terror you've constructed. The ability to destroy a planet is insignificant next to the power of the Force."},{"source":"Luke Skywalker","quote":"I want to come with you to Alderaan. There's nothing for me here now. I want to learn the ways of the Force and be a Jedi, like my father before me."},{"source":"Leia","quote":"No! Alderaan is peaceful. We have no weapons. You can't possibly…"},{"source":"Darth Vader","quote":"You are a part of the Rebel Alliance and a traitor! Take her away!"},{"source":"Leia","quote":"Dantooine. They're on Dantooine."},{"source":"Han Solo","quote":"Kid, I've flown from one side of this galaxy to the other. I've seen a lot of strange stuff, but I've never seen anything to make me believe there's one all-powerful Force controlling everything. There's no mystical energy field that controls my destiny. It's all a lot of simple tricks and nonsense."},{"source":"Luke Skywalker","quote":"All right. Well, take care of yourself, Han. I guess that's what you're best at, ain't it?"},{"source":"Darth Vader","quote":"You are a part of the Rebel Alliance and a traitor! Take her away!"},{"source":"Luke Skywalker","quote":"Alderaan? I'm not going to Alderaan. I've got to go home. It's late, I'm in for it as it is."},{"source":"Darth Vader","quote":"Don't be too proud of this technological terror you've constructed. The ability to destroy a planet is insignificant next to the power of the Force."},{"source":"Darth Vader","quote":"Don't underestimate the Force."},{"source":"Darth Vader","quote":"You are a part of the Rebel Alliance and a traitor! Take her away!"},{"source":"Luke Skywalker","quote":"Look, I can take you as far as Anchorhead. You can get a transport there to Mos Eisley or wherever you're going."},{"source":"Han Solo","quote":"You're all clear, kid. Let's blow this thing and go home!"},{"source":"Darth Vader","quote":"I find your lack of faith disturbing."},{"source":"Han Solo","quote":"Hokey religions and ancient weapons are no match for a good blaster at your side, kid."},{"source":"Luke Skywalker","quote":"I can't get involved! I've got work to do! It's not that I like the Empire, I hate it, but there's nothing I can do about it right now. It's such a long way from here."},{"source":"Leia","quote":"I'm surprised you had the courage to take the responsibility yourself."},{"source":"Leia","quote":"The more you tighten your grip, Tarkin, the more star systems will slip through your fingers."},{"source":"Darth Vader","quote":"Don't underestimate the Force."},{"source":"Ben Kenobi","quote":"I need your help, Luke. She needs your help. I'm getting too old for this sort of thing."},{"source":"Leia","quote":"What?!"},{"source":"Leia","quote":"I don't know what you're talking about. I am a member of the Imperial Senate on a diplomatic mission to Alderaan--"},{"source":"Han Solo","quote":"Still, she's got a lot of spirit. I don't know, what do you think?"},{"source":"Darth Vader","quote":"As you wish."},{"source":"Luke Skywalker","quote":"You mean it controls your actions?"},{"source":"Luke Skywalker","quote":"Oh God, my uncle. How am I ever gonna explain this?"},{"source":"Luke Skywalker","quote":"Alderaan? I'm not going to Alderaan. I've got to go home. It's late, I'm in for it as it is."},{"source":"Leia","quote":"The more you tighten your grip, Tarkin, the more star systems will slip through your fingers."},{"source":"Leia","quote":"I'm surprised you had the courage to take the responsibility yourself."},{"source":"Darth Vader","quote":"A tremor in the Force. The last time I felt it was in the presence of my old master."},{"source":"Darth Vader","quote":"Escape is not his plan. I must face him, alone."},{"source":"Luke Skywalker","quote":"I want to come with you to Alderaan. There's nothing for me here now. I want to learn the ways of the Force and be a Jedi, like my father before me."},{"source":"Darth Vader","quote":"He is here."},{"source":"Ben Kenobi","quote":"Your eyes can deceive you. Don't trust them."},{"source":"Luke Skywalker","quote":"I can't get involved! I've got work to do! It's not that I like the Empire, I hate it, but there's nothing I can do about it right now. It's such a long way from here."}],"headers":[{"header":"The Clone Wars"},{"header":"A New Hope"},{"header":"Revenge of the Sith"},{"header":"Imperial Star Destroyer"},{"header":"The Battle for Endor"},{"header":"The Force Unleashed"},{"header":"Return of the Jedi"},{"header":"Rebel Mission to Ord Mantell"},{"header":"The Phantom Menace"},{"header":"Knights of the Old Republic"},{"header":"The Sith Lords"},{"header":"Attack of the Clones"},{"header":"The Rebel Force"},{"header":"The Republic"},{"header":"The Empire Strikes Back"},{"header":"Revenge of the Sith"},{"header":"Jedi Academy"}]} 2 | --------------------------------------------------------------------------------