Link with a autofilled in coupon?

1 view
Skip to first unread message

John McLaughlin

unread,
Feb 4, 2010, 2:14:48 AM2/4/10
to Potion Store Discussions
Hi All,

I'm considering doing the macworld indie spotlight:

http://www.macworldexpo.com/indiespotlight

But the way they handle the 20% discount is via a special 'link' --
I'm wondering if there is some way to form a url to a potion store to
auto-fill the coupon code (so I can provide them a link like
http://mystore.com/?coupon=macworld)

I took a peek through but I didn't see anything obvious (but honestly
my Ruby skills are pretty weak and I haven't touched it in a long
time)

Thanks
-john

Brian Cooke

unread,
Feb 4, 2010, 6:05:04 AM2/4/10
to potion...@googlegroups.com
I haven't yet committed this back to my fork, but you can see a gist
of what I'm doing here:

http://gist.github.com/275736

Not the cleanest code, inline styles and all, but works for me.

And you can see it in action here:

https://store.madebyrocket.com/store?c=MWEXPODISCOUNT

hope that helps.

Best,
Brian

> --
> You received this message because you are subscribed to the Google Groups "Potion Store Discussions" group.
> To post to this group, send email to potion...@googlegroups.com.
> To unsubscribe from this group, send email to potion-store...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/potion-store?hl=en.
>
>

Mango

unread,
Feb 4, 2010, 2:19:08 PM2/4/10
to Potion Store Discussions
Thanks for the code, Brian. A question, and then a minor
contribution:

1. I'm trying to get the same thing set up, integrated your code, and
it works *except* that the "coupon code" field is not automatically
filled with the coupon. You can go here to see:

https://secure.wanderingmango.com/?c=MW2010

Now, "MW2010" should appear in the coupon field, but it doesn't. (If
the user fills it in manually, everything works as expected.) Any
ideas?

2. I discovered that I can use a global "percentage off" coupon by
going into the database and editing percentage to 20, and then
replacing this line in Brian's new.rhtml:

<%= number_to_currency product.price - @coupon.amount %>

with this line:

<%= number_to_currency (product.price - product.price *
@coupon.percentage/100) %>

Gleb Dolgich

unread,
Feb 4, 2010, 3:41:37 PM2/4/10
to potion...@googlegroups.com
On 4 Feb 2010, at 07:14, John McLaughlin wrote:

> I'm considering doing the macworld indie spotlight:
>
> http://www.macworldexpo.com/indiespotlight
>
> But the way they handle the 20% discount is via a special 'link' --
> I'm wondering if there is some way to form a url to a potion store to
> auto-fill the coupon code (so I can provide them a link like
> http://mystore.com/?coupon=macworld)

I made a quick and dirty patch to enable URLs like http://my-store-url.com/?coupon=ABCDEF01234567890. The patch consists of 2 parts:

http://gist.github.com/295073 -- enables pre-filling coupon code when a store URL like above is clicked;

http://gist.github.com/295075 -- makes coupon code from URL take priority over any session-stored coupon code.

--
Gleb Dolgich
http://pixelespressoapps.com

Paul Kim

unread,
Feb 4, 2010, 3:55:01 PM2/4/10
to potion...@googlegroups.com
Thanks for sharing this. I had something similar but didn't have the nice touch where you showed the updated price on the store page with the old one struck through. I hope you don't mind me appropriating it.

One thing is that I also look for a cookie. Instead of having my store be the landing page, I give an URL to my main product page. It looks at the param and sets a cookie such that when the user does get around to going to the store, they get the discount. Here's my simple patch to your patch to order_controller.rb:

http://gist.github.com/295088

The part where you set the cookie I leave as an exercise to the reader.

paul

Stefan Reitshamer

unread,
Feb 4, 2010, 11:26:37 AM2/4/10
to potion...@googlegroups.com
Thanks Brian, that was super helpful!
I had to also put the coupon code into the coupon text field so that it would go into the order.
I stuck it in the session since that's where the text field expected it (might be hacky, it's my 3rd day doing Ruby/Rails development):

--- a/app/views/store/order/new.rhtml
+++ b/app/views/store/order/new.rhtml
@@ -36,7 +36,9 @@ $(document).ready(function(){
<%= text_field "items", product.id, :size => "3", :value => @qty[product.code], :autocomplete => "off", :class => "qty" -%>
@
<strong id="item_<%=product.id %>_price">
- <% if @coupon && !@coupon.expired? %>
+ <% if @coupon && !@coupon.expired?
+ session[:coupon_text] = @coupon.coupon if @coupon;
+ %>
<strike>
<%= number_to_currency product.price %>
</strike>

- Stefan

On Feb 4, 2010, at 6:05 AM, Brian Cooke wrote:

John McLaughlin

unread,
Feb 6, 2010, 3:26:07 AM2/6/10
to Potion Store Discussions
Hey guys,

Thanks for the great responses -- It was much more than I was
expecting! I'm happy to say my store is now auto-fillable!

-john

Reply all
Reply to author
Forward
0 new messages