Show Accessory Products with Price (and IDEALLY an Add to Cart button too)

Permalink Browser Info Environment
What I want to do (under Product Details) is show Accessory Products. So they are specific products I would select... "Accessories" for the current product.
As such, I also want to Show the Price (and IDEALLY an Add to Cart button too).

Is this possible and easily done?

Type: Discussion
Status: In Progress
OKDnet
View Replies:
JohntheFish replied on at Permalink Reply
JohntheFish
Hi Owen

Just doing some housekeeping on support requests and I found this one unanswered. I suspect its one of those where c5 fails to send the PM.

Anyway, although its a bit late, do you need help with this?
OKDnet replied on at Permalink Reply 2 Attachments
OKDnet
John,

Actually we did this in PM, which looking back is a nightmare to try and go back to for reference. It's better here to refer back to.

While I have this working, it's not ideal. The price and the cart work. The issue is the different cases. I'm not going to worry about the "Call for Price" case because we're eliminating that case. There is still the "Regular Price Only" case, and the "List Price/SpecialPrice". Right now I just created two different stacks and use the appropriate one.

The second case is "working", but the check for if there is a special price only works correctly if there is a special price. So I'm using it only on pages where there is a special price..

This is the code
[% 
// get the regular and special prices, formatted, save to memories
CURRENT_PRODUCT PRODUCT_PRICE FORMAT_PRICE SAVE 'frp' 
CURRENT_PRODUCT PRODUCT_SPECIAL_PRICE FORMAT_PRICE SAVE 'fsp'
// compare
'fsp'  RECALL NE (  'frp'  RECALL )
// false, so they are equal, so format the regular price
ZERO_AS_THEN_END ( 'Regular price only {{frp}}' FORMAT )
//true, so there is an offer, so format the special price
'<span class="product_strikethrough"> List Price {{frp}}</span><br> <span class="product_specialoffer">Sale Price {{fsp}}</span>' FORMAT %]
<p>
[% CURRENT_PRODUCT ADD_TO_CART_BUTTON "Add To Cart" 1 %]


Ideally I could use the same on all. see the 2 attached to see what the above results in (both when there is a special price, and then if there is not).

So, since that's not working, I'm just using the other stack with
[% 
// get the regular price, formatted, save to memory
CURRENT_PRODUCT PRODUCT_PRICE FORMAT_PRICE SAVE 'frp' 
'<span class="product_regularprice"> {{frp}}</span>' FORMAT %]
<p>
[% CURRENT_PRODUCT ADD_TO_CART_BUTTON "Add To Cart" 1 %]


At least part of the problem is certainly exactly the same as what you found when we did the attributes. For reference, you said

"the problem seems to be that a special price of 0 (no special price) gets formatted to $0.00, so is not a zero string because it contains the formatting, it is not equal to the regular price and gets returned.
So there are actually 2 special cases to handle
1. Special price is zero (not set)
2. Special price not equal to regular price (the original premise)
The following variation of the expression saves the unformatted regular price and compares to the unformatted special price."
ATTRIBUTE_OBJECT SAVE 'my_page'
PRODUCT_FOR_PAGE SAVE 'my_product'
PRODUCT_PRICE 
ZERO_AS_THEN_END ( "Call for Pricing" ) 
SAVE 'rp' 
FORMAT_PRICE SAVE 'frp' 
'my_product' RECALL 
PRODUCT_SPECIAL_PRICE SAVE 'sp'
/* case of special price is zero */
ZERO_AS_THEN_END ( 'Regular price only {{frp}}' FORMAT ) 
'sp' RECALL NE ( 'rp' RECALL )
/* case of special is equal to regular price */
ZERO_AS_THEN_END ( 'Regular price only {{frp}}' FORMAT ) 
/* case of special price is not the same as regular price */
FORMAT_PRICE SAVE 'fsp'
OKDnet replied on at Permalink Reply
OKDnet
I got it all working (getting the hang of this).
[% 
// get the regular and special prices, formatted, save to memories
CURRENT_PRODUCT PRODUCT_PRICE ZERO_AS_THEN_END ( " " ) 
SAVE 'rp'
CURRENT_PRODUCT PRODUCT_PRICE FORMAT_PRICE SAVE 'frp' 
CURRENT_PRODUCT PRODUCT_SPECIAL_PRICE SAVE 'sp'
/* case of special price is zero */
ZERO_AS_THEN_END ( '<span class="product_regularprice"> {{frp}}</span>' FORMAT ) 
'sp' RECALL NE ( 'rp' RECALL )
/* case of regular price only */
ZERO_AS_THEN_END ( 'Regular price only {{frp}}' FORMAT )
/* true, so there is an offer, so format the special price */
FORMAT_PRICE SAVE 'fsp'
'<span class="product_strikethrough"> List Price {{frp}}</span><br> <span class="product_specialoffer">Sale Price {{fsp}}</span>' FORMAT %]
<p>
JohntheFish replied on at Permalink Reply
JohntheFish
Great. Splitting the buy button out into a separate token was a good move. While MD can be used to come up with some quite complex expressions, a series of independent expressions each in their own token keeps it simpler and easier to maintain.

Watch out for comments and newlines getting mashed up by tinyMCE if you put this in a content block. In an HTML block you can get away with pretty much anything.

Thanks for posting the reviews.
OKDnet replied on at Permalink Reply 2 Attachments
OKDnet
Actually, not only did I speak a little too soon, but the Add to Cart expression (the 2nd one) was breaking both the regular price case and the special price case. Not to mention I had but the "Call for Pricing" text string with it's html etc. in the wrong ZERO_AS_THEN_END.

EDIT
I can't see why this isn't working.
It works in 1st case (No price, so Call for Price),
But I do not understand why I'm getting the results I am in the 2nd and 3rd case
2nd case - there is a special price (see 1st attached screenshot)
3rd case - only a regular price (see 2nd attached screenshot)
[% 
// get the regular and special prices, formatted, save to memories
CURRENT_PRODUCT PRODUCT_PRICE ZERO_AS_THEN_END ( '<div class="fa fa-phone fa-2x"><h3 style="color: #660000; display: inline;"> Call for Pricing (913) 961-4455 </h3></div> <p>' ) 
SAVE 'rp'
FORMAT_PRICE SAVE 'frp' 
CURRENT_PRODUCT PRODUCT_SPECIAL_PRICE SAVE 'sp' 
// case of special price is zero i.e regular price only 
ZERO_AS_THEN_END ( '<span class="product_regularprice"> {{frp}}</span>' FORMAT )
'sp' RECALL NE ( 'rp' RECALL )
ZERO_AS_THEN_END ( '<span class="product_strikethrough"> List Price {{frp}}</span><br> <span class="product_specialoffer">Sale Price {{fsp}}</span>' FORMAT ) %]
<p>
[% CURRENT_PRODUCT PRODUCT_PRICE ZERO_AS_THEN_END ( " " ) CURRENT_PRODUCT ADD_TO_CART_BUTTON "Add to Cart" 1 %]</p>
JohntheFish replied on at Permalink Reply
JohntheFish
About to finish for dinner. Quick observation.
I cant see you saving fsp anywhere, so the format can't fill it in
OKDnet replied on at Permalink Reply 2 Attachments
OKDnet
I was thinking that, so I tried the following, but it resulted in what yoiu see attached (the first is the case of a special price, and the 2nd is just a normal price)
[% 
// get the regular and special prices, formatted, save to memories
CURRENT_PRODUCT PRODUCT_PRICE ZERO_AS_THEN_END ( '<div class="fa fa-phone fa-2x"><h3 style="color: #660000; display: inline;"> Call for Pricing (913) 961-4455 </h3></div> <p>' ) 
SAVE 'rp'
FORMAT_PRICE SAVE 'frp' 
CURRENT_PRODUCT PRODUCT_SPECIAL_PRICE SAVE 'sp'
FORMAT_PRICE SAVE 'fsp'
// case of special price is zero i.e regular price only 
ZERO_AS_THEN_END ( '<span class="product_regularprice"> {{frp}}</span>' FORMAT )
'sp' RECALL NE ( 'rp' RECALL )
ZERO_AS_THEN_END ( '<span class="product_strikethrough"> List Price {{frp}}</span><br> <span class="product_specialoffer">Sale Price {{fsp}}</span>' FORMAT ) %]
<p>
[% CURRENT_PRODUCT PRODUCT_PRICE ZERO_AS_THEN_END ( " " ) CURRENT_PRODUCT ADD_TO_CART_BUTTON "Add to Cart" 1 %]</p>


The "Sales Price Price" output makes no sense to me. Where is that coming from?
OKDnet replied on at Permalink Reply
OKDnet
I got it.

I think the above was about right, but the issue was a missing space somewhere (not sure where), perhaps after a comment?

Anyway, I tested all 3 cases, and this is the working code

[% 
// get the regular and special prices, formatted, save to memories
CURRENT_PRODUCT PRODUCT_PRICE ZERO_AS_THEN_END ( '<div class="fa fa-phone fa-2x"><h3 style="color: #660000; display: inline;"> Call for Pricing (913) 961-4455 </h3></div> <p>' ) 
SAVE 'rp' 
FORMAT_PRICE SAVE 'frp' 
CURRENT_PRODUCT PRODUCT_SPECIAL_PRICE SAVE 'sp' 
FORMAT_PRICE SAVE 'fsp' 
RECALL 'sp' 
/* case of special price is zero */
ZERO_AS_THEN_END ( '<span class="product_regularprice"> {{frp}}</span>' FORMAT ) 
'sp' RECALL NE ( 'rp' RECALL ) 
/* case of special is equal to regular price */
ZERO_AS_THEN_END ( '<span class="product_regularprice"> {{frp}}</span>' FORMAT ) 
/* case of special price is not the same as regular price */
FORMAT_PRICE SAVE 'fsp'
JohntheFish replied on at Permalink Reply
JohntheFish
If you want to risk any changes, you are saving fsp twice, so should be able to get rid of one of them.

I am going to be off chasing fishes for 17 days from 9 July, so if there are any more MD snippets in the current project you may need help with, it will need to be within the next few days.
OKDnet replied on at Permalink Reply
OKDnet
OK, thanks.
I don't have anything right now, but appreciate the heads up. Have fun!

I was thinking though, is there any reason why it wouldn't be a good idea to Magic Data enable this?
http://www.concrete5.org/marketplace/addons/php-code-block...

For more complicated things, I thought sometimes it might be easier to combine PHP and MD.

concrete5 Environment Information

NA

Browser User-Agent String

Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.