Comments

krcha created an issue. See original summary.

mglaman’s picture

Project: Belgrade » Commerce Demo
czigor’s picture

Status: Active » Needs review
StatusFileSize
new0 bytes

Added 5 promotions and one coupon to each. We display a message on product/123 about which coupons can be used in relation to that product.

czigor’s picture

StatusFileSize
new7.57 KB

That's going to be better.

mglaman’s picture

  1. +++ b/commerce_demo.module
    @@ -81,3 +81,23 @@ function commerce_demo_preprocess_breadcrumb(&$variables) {
    +function commerce_demo_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
    

    We could just target commerce_demo_commerce_product_view to remove one entity type check

  2. +++ b/commerce_demo.module
    @@ -81,3 +81,23 @@ function commerce_demo_preprocess_breadcrumb(&$variables) {
    +  \Drupal::messenger()->addStatus(t('The following coupon codes can be used with this product:'));
    +  \Drupal::messenger()->addStatus(t('"BUY1GET2" Buy 1 get 2'));
    +  \Drupal::messenger()->addStatus(t('"ORDER3USD" 3 USD discount on whole order'));
    +  \Drupal::messenger()->addStatus(t('"FIFTEENPERCENT" 15% discount on an order'));
    ...
    +    \Drupal::messenger()->addStatus(t('"TYPEWRITER" 20% discount on typewriter'));
    ...
    +    \Drupal::messenger()->addStatus(t('"CLOCKDISCOUNT" 4 USD discount on clock'));
    

    Let's just do $messenger = ... once and invoke that

  3. +++ b/commerce_demo.module
    @@ -81,3 +81,23 @@ function commerce_demo_preprocess_breadcrumb(&$variables) {
    +  if ($entity->id() == 5) {
    ...
    +  if ($entity->id() == 21) {
    

    We should probably target the UUID here, since the UUID in our export persists.

    And I'm pretty sure that our conditions target UUIDs.

    There's a chance someone may have made a product before importing? Maybe?

czigor’s picture

StatusFileSize
new7.59 KB

Fixed all the things as all the things made sense.

mglaman’s picture

Assigned: Unassigned » mglaman
Status: Needs review » Needs work

Wrapping this up.

The patch dies if commerce_promotion is not enabled.

+++ b/content/commerce_promotion.commerce_promotion.yml
@@ -0,0 +1,75 @@
+  order_types:
+    - default

We need to also target `physical`

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new8.06 KB

This fixes install. Discussed w/ czigor and it would be good to add some kind of messaging in the checkout as well. I forgot what coupon codes I could use by the time I hit checkout.

mglaman’s picture

Status: Needs review » Needs work
+++ b/content/commerce_promotion.commerce_promotion.yml
@@ -0,0 +1,80 @@
+  name: 'Buy 1 Get 2'
...
+    target_plugin_configuration: 'a:7:{s:12:"buy_quantity";s:1:"1";s:14:"buy_conditions";a:1:{i:0;a:2:{s:6:"plugin";s:23:"order_item_product_type";s:13:"configuration";a:1:{s:13:"product_types";a:3:{i:0;s:8:"clothing";i:1;s:7:"default";i:2;s:6:"simple";}}}}s:12:"get_quantity";s:1:"1";s:14:"get_conditions";a:1:{i:0;a:2:{s:6:"plugin";s:23:"order_item_product_type";s:13:"configuration";a:1:{s:13:"product_types";a:3:{i:0;s:8:"clothing";i:1;s:7:"default";i:2;s:6:"simple";}}}}s:10:"offer_type";s:10:"percentage";s:16:"offer_percentage";s:1:"1";s:12:"offer_amount";N;}'

This is configured wrong and is currently acting as a B1G1

mglaman’s picture

Assigned: mglaman » Unassigned
Status: Needs work » Needs review
StatusFileSize
new11.68 KB
new167.5 KB
new1.02 MB

Okay, here is the patch I'm preparing to commit.

The checkout shows available coupons that can be used for the order

And viewing a product shows a message

mglaman’s picture

Status: Needs review » Needs work
+++ b/src/ContentExporter.php
@@ -246,6 +250,30 @@ class ContentExporter {
+      $variations[$coupon->uuid()] = $this->export($coupon);
+      // The array is keyed by UUID, no need to have it in the export too.
+      unset($variations[$coupon->uuid()]['uuid']);
+    }
+    $export['variations'] = $variations;

Copy paste fail, times two.

I had exported coupon changes and found them lost. Manually replaced and fixed this without manually testing the export, again. 🤦🤦

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new11.31 KB

Updated patch.

mglaman’s picture

+++ b/src/ContentImporter.php
@@ -197,24 +201,33 @@ class ContentImporter {
+  protected function processReferences(array $values, EntityInterface $entity, $field_name) {
...
+      $entity = $this->importEntity($entity_type_id, $entity_values);

Slightly concerned here we're overwriting a parameter.

mglaman’s picture

StatusFileSize
new11.67 KB

Okay, here we go!

mglaman’s picture

StatusFileSize
new11.67 KB

Here's some more tweaks. Missed the promotion_id back reference in the export. Also B1G2 to B1G1

mglaman’s picture

Assigned: Unassigned » mglaman
Status: Needs review » Needs work

Discussed with rszrama, and we want to make the demo coupon text on checkout more obvious that it's part of the demo.

mglaman’s picture

Assigned: mglaman » Unassigned
Status: Needs work » Needs review
StatusFileSize
new311.3 KB
new1.4 KB

Example:

  • mglaman committed 034d01e on 8.x-1.x
    Issue #2982071 by mglaman, czigor, krcha: Add coupon example
    
mglaman’s picture

Status: Needs review » Fixed

\o/ landed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.