Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have one Coupon for each CouponCode #2116

Merged
merged 20 commits into from
Jun 26, 2017
Merged

Conversation

michalrus
Copy link
Contributor

@michalrus michalrus commented Jun 9, 2017

Resolves #1489

So what this does is:

  • we get rid of two requests to first create a Coupon, and only then some CouponCodes. Now the CreateCoupon payload has two more fields:
    • singleCode :: String, if you want a single code
    • generateCodes :: ThatPreviousGenerateCodes, which is { prefix :: String, quantity :: Int, length :: Int}, if you want multiple codes.
    • And you’re free to use both at the same time. 😊 (But at least one!)
  • And now, each CouponCode gets its own Coupon,
  • so the coupon creation endpoint will return a list of what it used to return, one item per coupon (+ code).
  • Each element of that response will also have a code :: String.
  • Search views are unchanged, and just work.
  • No migrations are needed.

@bagratinho, I need your help with redoing that part of Ashes that’s sending the coupon creation request and (possibly) parsing its response. 🙏 📿

@@ -48,7 +48,7 @@ object CouponCodes
requestedLimit >= prefixSize + minSuffixSize
}

def generateCodes(prefix: String, codeCharacterLength: Int, quantity: Int, attempt: Int = 0): Seq[String] = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙄

mutateOrFailures {
CouponManager.getCodes(id)
}
// TODO: get rid of this route → code is already provided in CouponResponse.Root @michalrus
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it won't be used, then yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bagratinho, when tackling this, would you verify that we don’t use

return Api.get(`/coupons/codes/${id}`);
and remove it, too?

CouponManager.update(id, payload, context, auth.model)
}
} ~
// FIXME: unused? @michalrus
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bagratinho tells me we’re not updating coupons. 🔥?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's UI for that. @bswineford ?

CouponResponse.build(context, code, coupon, fas.form, fas.shadow)
}

// TODO: really? Two log events for each coupon code? @michalrus
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmmmm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably for coupons and coupon codes separately. I think this can be changed to one activity logging. Same for bulk gen

Copy link
Contributor Author

@michalrus michalrus Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why does .couponCreated change scope and .singleCouponCodeCreated doesn’t? :<

https://github.com/FoxComm/highlander/pull/2116/files#r121897193

_ ← * <~ CouponCodes.createAll(unsaved)
_ ← * <~ LogActivity().multipleCouponCodeCreated(coupon, Some(admin))
} yield generated
code <- CouponCodes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, cute, git-diff decided we’re copying code enough so that it can show it like that. 😛

CouponManager.create(payload, context.name, None).map { newCoupon
source.copy(formId = newCoupon.id)
CouponManager.create(payload, context.name, None).map { newCoupons
newCoupons.map(newCoupon => source.copy(formId = newCoupon.id))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what do these SimpleModels actually give us, over using just Models?

Apart from increasing the amount of code to maintain, that is. 😛

generateCodes: Option[GenerateCouponCodes])

// FIXME: unused? @michalrus
//case class UpdateCoupon(attributes: Map[String, Json], promotion: Int)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Seems you can remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s wait for @bswineford / @bagratinho, but I don’t see UI for editing coupons either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or whatever, I’m removing this.

mutateOrFailures {
CouponManager.getCodes(id)
}
// TODO: get rid of this route → code is already provided in CouponResponse.Root @michalrus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it won't be used, then yes

CouponManager.update(id, payload, context, auth.model)
}
} ~
// FIXME: unused? @michalrus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's UI for that. @bswineford ?

.insert(couponFormAndShadow.form, couponFormAndShadow.shadow, payload.schema))

coupons = formsAndShadows.map(
fas =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs reformat?

CouponResponse.build(context, code, coupon, fas.form, fas.shadow)
}

// TODO: really? Two log events for each coupon code? @michalrus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably for coupons and coupon codes separately. I think this can be changed to one activity logging. Same for bulk gen

def generate(code: String)(implicit aa: TestAdminAuth): HttpResponse =
POST(s"$rootPrefix/coupons/codes/generate/$formId/$code", aa.jwtCookie.some)
}
// TODO: unused @michalrus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@michalrus
Copy link
Contributor Author

michalrus commented Jun 13, 2017

[@Anna-ZZZ] bugfix PR probably needs an upd to API docs

& an appliance for Bagrat ⇒ https://foxcommerce.slack.com/archives/C1DMVNVLM/p1497361174779856

}

_ ← * <~ coupons.headOption.traverse { firstCoupon ⇒
// TODO: Should they override scope? (`LogActivity().withScope(scope)`) @michalrus
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did .couponCreated change scope and .singleCouponCodeCreated didn’t? :<

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe…

@@ -20,7 +20,7 @@

### View Illuminated [GET /v1/promotions/{context}/{id}/baked]

Return illuminated version of promotion.
Return illuminated version of promotion. FIXME: This is very behind right now. @michalrus
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…?

@michalrus
Copy link
Contributor Author

Current status: blocked by make up & make provision not working. Cf. https://foxcommerce.slack.com/archives/C4G19344X/p1497429457377966

@bagratinho
Copy link
Contributor

#2184 Ashes changes

@michalrus
Copy link
Contributor Author

michalrus commented Jun 16, 2017

@annappropriate
Copy link
Contributor

Conflict

@michalrus
Copy link
Contributor Author

michalrus commented Jun 22, 2017

When trying to redeploy:

TASK [dev/flyway : Repair Geronimo Database] ***********************************
fatal: [10.240.0.25]: FAILED! => {"changed": true, "cmd": "FLYWAY_HOME=/usr/local/share/flyway-4.0.3 /usr/local/share/flyway-4.0.3/flyway -locations=filesystem:sql/ -configFile=sql/flyway.conf repair", "delta": "0:00:00.298825", "end": "2017-06-22 13:16:18.777771", "failed": true, "rc": 1, "start": "2017-06-22 13:16:18.478946", "stderr": "ERROR: Unable to obtain Jdbc connection from DataSource (jdbc:postgresql://db.service.consul/geronimo?user=geronimo) for user 'geronimo': FATAL: role "geronimo" does not exist", "stdout": "Flyway 4.0.3 by Boxfuse", "stdout_lines": ["Flyway 4.0.3 by Boxfuse"], "warnings": []}

EDIT: twice. I’ll try to disable it.

@michalrus
Copy link
Contributor Author

michalrus commented Jun 22, 2017

@michalrus
Copy link
Contributor Author

Copy link
Contributor

@jmataya jmataya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a couple things that we should change:

  • For item qualifiers, give an option for any product to qualify

  • Change text of "Items for qualify" to "Qualifying items"

    foxcommerce_-_new_promotion
  • This UX feels pretty confusing -- what does it mean?

    foxcommerce_-_new_promotion
  • We don't seem to be forcing a choice on usage rules. What does this state mean?

    foxcommerce_-_jeff_s_auto_applying_yo
  • I set my offer on a promotion to be free shipping, it appears that I'm going to be charged shipping, even though I'm not

    foxcommerce_-_cart_br10005
  • If an exclusive promotion is on the cart and I try to add a promotion that is not exclusive, it kicks the exclusive promotion off

We don't necessarily need to fix up all of this, but wanted to highlight the issues.

@jmataya
Copy link
Contributor

jmataya commented Jun 23, 2017

Also, items based promotions don't seem to be working for me.

@bagratinho
Copy link
Contributor

@jmataya I would say we better create new issue(s) for points described above in your comments, IMO that should be tackled separately, not in this PR, as this one is related to coupon creation. Not promo.

@michalrus
Copy link
Contributor Author

Yes, let’s have small diffs, it would be easier!

@annappropriate
Copy link
Contributor

@jmataya I created issues for everything you highlighted, except for the last one.

If an exclusive promotion is on the cart and I try to add a promotion that is not exclusive, it kicks the exclusive promotion off

I believe we have decided that user actions of applying coupons are more important than auto-applied promos. Correct me if I'm wrong tho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coupons. Bulk generated codes are listed in 1 line on the coupons list.
5 participants