New to UberCart, your patience (and cooperation) please! :D

Posts: 9
Joined: 12/20/2007

Hey guys,

Quickie about myself:
I'm new to UberCart (toying with Drupal/Ubercart for about a month), and beginner in PHP and other web languages (HTML is my neck of the woods), but I'm not afraid to get my hands dirty. I'm launching a T-Shirt-like store, but for Hockey Jerseys. UberCart was an obvious choice because its Free, open-source, and well supported. Who could ask for more? Smiling

Let me say this -- my site is getting there. I'm really getting the grasp of what does what -- and I've been getting my site ready SEO wise, but the problem is, I'm stuck when it comes to layouts. Product page, specifically.

So, I've put together a little presentation of what I want to do -- excuse the lameness of my photoshop skills! I've numbered the issues from 1 - 4.
http://www.killerjerseys.com/images/project.jpg

(If needed:) The Live test page I'm working with is: http://www.killerjerseys.com/content/habs
(Side-note: I've been using Contemplate for the layout output.)

1) Is there a way to force someone, via JavaScript popup or AJAX, in selecting a size before Adding to Cart? If so, how would I implement it? With Contemplate, I can't address specific Attributes, so I wouldn't know how to approach this.

2) I want to make the attributes below this attribute (IE: Name on Back, Number on Jersey, etc) to be grayed out unless the "YES" option is true. Possible? Also, Is it possible to make this radio instead of drop down? If so, How?

3) How can I limit the characters allowed to be input in this box? If I left it unlimited (or browser max), I'd be out of business faster than you could say "lmao." Same applies for the "number on the jersey" field (I haven't added it yet)

4) Is it possible to move the Price above the "Add To Cart" buttons?

Now, if using Contemplate is the wrong way to approach this, let me know -- but, Is there a way to make a selectable template per product type? I mean, this particular product is a Jersey, but what if I want to throw Hats or Gloves into the equation? I wouldn't have the "Make it your own!" header there, and therefore would have to change the theme...

Thanks for bearing with me. I tend to blabber, I know Sticking out tongue. I'm not a programmer by any means, but like I've said before, I like to get my hands dirty. Any help at all is appreciated, as I'm kind of stumped and lost at this point. If it takes alot of your personal time to help me with this, please feel free to e-mail me, we could work something out.

Thanks guys, and keep up the great work!

Posts: 9
Joined: 12/20/2007

Bump, fell off first page!

I'm not looking for step-by-step, per se, anything will do!

Posts: 1293
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

#1 is something that I'd like to see built into core - the ability to "require" attribute selection in the order page. Right now I think you'd have to write a small custom module and invoke hook_form_alter() to require those fields. You can see an example of how it's done in the Gift certificate Contribution. It would simply be adding '#required' => TRUE), to that form's particular element.

#2 is probably a Javascript addition, I'd looking to jQuery to do your bidding. You'd have to make calls to onChange and whatnot, no need to specific since jQuery can traverse down the DOM using the elements' IDs. (Sorry if this is all babble to you, you'll understand eventually Smiling

#3 - Using hook_form_alter, set the attribute '#maxlength' => 25 or whatever # of chars you want to restrict to.

#4- Again, using hook_form_alter (sensing a pattern yet? Eye-wink), you can add '#weight' => 10 or some higher number to sink the element you want towards the bottom. Although for styling your add to cart form (and not affecting its functionality such as the above issues) you could put the Submit form pretty much wherever you want. (On my site, I've gotten rid of it entirely - except for when an attribute is selected - and made it into a button.)

The main issue is Contemplate doesn't interact with the Forms API, so you can't change how the form gets rendered, you can only affect its output - and then interact with the data that it's giving you. In other words I could spit out a list of "Other Products in this Vocabulary" but I couldn't say "make all fields required". Does this make sense?

Sorry if some of this is over your head. Definitely start looking through the Contribs, they will help a lot, and also the drupal.org site. I would also recommend Pro Drupal Development by Matt Westgate and John VanDyk. The book is worth its weight in gold. (And the community here rocks as well!)

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 27
Joined: 01/17/2008

Thanks a bunch for this information, torgos! I knew this was a bit over-my-head, but I'll buy the Drupal Pro Dev book off Amazon to see if I can take a stab at it.

I'm running a hockey related site, so, as you could imagine, I need the site up and running ASAP for the playoffs. I'll probably have to get someone to write it for me :|

Regardless, this is a light at the end of the tunnel, and thanks for the guidance!

Another question -- is it possible to have multiple Contemplate layouts for different types of products? Like I said before, the layout of the jersey page may not necessarily be the same as a hat page, etc.

Posts: 1293
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

There are a couple ways you could do it, probably the easiest method without writing a custom hook or a bunch of conditionals, is to create a Product Class. That'll allow you to create templates for each class .. if I'm remembering correctly. Pretty sure the answer is yes, though Smiling

EDIT: Now I remember. In your store product settings you can choose node types to assign as a product; so one trick would be to create a node type for whatever product you want to look differently and then create a new template for that product.

I know there are a couple other ways to do it that involve a bit more time and code but, this should steer you in the right direction.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 27
Joined: 01/17/2008

Cool stuff, Torgos... that's really helpful information, thanks a bunch!

Final question (hopefully!) -- how do I change the output of my search to something that resembles what the Catalog looks like in Grid? Is that views?

Posts: 301
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

Ryan, would you consider a patch for adding 'required' to attributes? This would add a Required checkbox under the Order field on the Manage Attributes screen which would then show as the default in a checkbox next to Remove on the Edit Attributes screen of a product. That might sound a bit confusing, but I think that would work out.

Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

I'd run it by Lyle since he knows the module more, but I don't see why not. I guess the issue to consider is do all "required" attributes start with no default selected and will it be possible to include a "Please select..." line like on the checkout pages for zones?

Posts: 301
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

I pictured it working with the default option still being recognized but in the absence of a default option a "Please select..." line would be added as the default. And in the case of an attribute with no options the text field would work like any other required field.

This would essentially mean that using a default option and making an attribute required would serve very little purpose as it wouldn't be easily possible for them to unselect an option on that field. So perhaps setting up an attribute as required would eliminate the ability to set a default option or would simply ignore it and place a message on the admin side stating that default options are ignored for required attributes...and then it would behave as stated above in the absence of a default option.

Posts: 1293
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Ryan wrote:
I'd run it by Lyle since he knows the module more, but I don't see why not. I guess the issue to consider is do all "required" attributes start with no default selected and will it be possible to include a "Please select..." line like on the checkout pages for zones?

That's my recommendation, to make it foolproof. The reflexive nature of "clicking to add to cart" could mean the customer inadvertently selecting the default option, without realizing they have a choice. I'd suggest that, if attributes exist and the select list is being displayed, have it set to "Please select the [option name]" or something similar; and if the user attempts to add it to the cart (using Cart Links or the add button) it kicks them back with a "You must choose.." message.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 301
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

Well...here is a small diff that adds required attributes.

First off, update.php will need run since the install file adds a new field, 'required', to the uc_product_attributes table.

The changes will add a 'Required' checkbox on an individual product's attribute settings page. I decided to make this product specific, although a checkbox could be added to the general Attribute settings page and the product could inherit that by default in the same way that Attribute prices/costs/etc. work.

A product's attribute with options still requires a default option even if the attribute is required, but on the attribute settings page the Default Option will show as n/a, the same as it does for an attribute with no options. (this could be changed to ignored, ignored when required, or anything like that).

On the cart page, required attributes will be set to '#required' => true and in the case of attributes with options, a select box will show with a default first option as 'Please select an option'

The patch also does whitespace trimming that Komodo does automatically which explains a large part of the diff file. It should apply fine to the latest Bazaar code.

If anyone wants to test that out I think it might be a decent start towards having Required Attributes. Lyle, I guess that is directed mostly at you to see if you want to consider adding this sort of functionality to core.

AttachmentSize
required_attribute.diff11.01 KB
Posts: 2244
Joined: 08/07/2007
AdministratoreLiTe!

Thanks, cYu. I committed this patch to the repository. Anybody who's getting the updated code, remember to run update.php.

Posts: 301
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

Cool stuff. Not sure about other attribute related modules, but I know at least the Ajax Calculated Field module will need updated to account for this extra option potentially showing up on attributes now. So if things break...that is probably the culprit.

Posts: 27
Joined: 01/17/2008

I'll double check on the AJAX calculated field in my install -- I need that to work, too Sticking out tongue

EDIT: ah, good point... doesn't work with the attribute when "required" is true, nor with a separate attribute. Gah, I wish I could contribute more -- I feel so useless Sad Amazon better pull through with that Pro Drupal book soon!

Posts: 301
Joined: 11/19/2007
Bug FinderGetting busy with the Ubercode.

Actually, I'm reviewing the AJAX attribute calc functionality right now and it looks like it is behaving the way I'd want it to. When the page first loads for a required attribute it will show 'Please select an option' but then once an option is selected and the select box is re-created this option has no reason to show up. KillerJerseys, can you describe what you mean by

KillerJerseys wrote:
doesn't work with the attribute when "required" is true, nor with a separate attribute.

Posts: 27
Joined: 01/17/2008

haha! When I trashed my Drupal install, I forgot to re-install your AJAX calculator mod... Sticking out tongue

All is well... sorry about that cYu.