Basic cart is a very simple shopping cart / checkout process for Drupal, that just sends 2 emails after each order. Along with the shopping cart, this module also provides a block where you can view your cart's content. It's ideal for small websites with only a few products or other content types being sold, for example travel offers.
Main difference from Ubercart and Commerce
The main difference from Ubercart and Commerce is the possibility of choosing the content types that can be added to the cart. It also doesn't bother you with the Product SKU, that can be a pain when you have just a few products.
Features
- The possibility of choosing the content types that can be added to the cart.
- The possibility of sending, or not, an email to the customer once an order is placed.
- Custom email messages for both the site administrator and the customer, along with the order details.
- A block with the contents of your shopping cart.
Project page: http://drupal.org/sandbox/dicix/1397698
Git clone: git clone http://git.drupal.org/sandbox/dicix/1397698.git basic_cart
Drupal version: Drupal 7.
Reviews of other projects
http://drupal.org/node/1396674#comment-5519858
http://drupal.org/node/1417258#comment-5519992
http://drupal.org/node/1418580#comment-5526272
http://drupal.org/node/1421888#comment-5549636
http://drupal.org/node/1422852#comment-5539156
http://drupal.org/node/1423138#comment-5539296
http://drupal.org/node/1429906#comment-5591410
http://drupal.org/node/1462634#comment-5681064
http://drupal.org/node/1423362#comment-5681212
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | drupalcs-result.txt | 2.77 KB | klausi |
| #25 | Screen-Shot-2012-02-12-at-2.18.38-PM.jpeg | 23.52 KB | alex dicianu |
| #14 | drupalcs-result.txt | 8.19 KB | klausi |
| #10 | basic-cart-thank-you.png | 15.5 KB | Niklas Fiekas |
| #7 | drupalcs-result.txt | 10.54 KB | klausi |
Comments
Comment #1
wadmiraal commentedHi,
You should remove the LICENSE.txt file. It will be added by the packaging system. I see a few coding standard issues. You might want to check out the coder module to help you with that.
Just by quickly reading through your code:
basic_cart.admin.inc:
could simply be
Actually, the entire form could use system_settings_form() (not required though - but much easier).
I also get a PHP Notice:
In the code, line 11:
UI / UX suggestion: line 230 in basic_cart.cart.inc:
is an error. Use the error class:
It would be interesting to have a quantity field, don't you think ? It's a bit weird to have to add a product 10 times to your cart if you want 10 items.
Comment #2
alex dicianu commentedHi,
Thanks for your input. I've done the following modifications:
- removed LICENSE.txt
- modified
'#default_value' => !empty($checked_types) ? $checked_types : array(),tovariable_get('basic_cart_content_types', array()),- got rid of that notice
- added the "error" here:
drupal_set_message(t('There was a problem in submitting your order. Please try again later.'), 'error');- added quantity fields in the shopping cart
- ran a verification with the coder module
Hope it will work better now ...
Comment #3
wadmiraal commentedOK, Coder agrees with you ;-). Good work.
Carefull, in your basic_cart_cart_render.tpl.php (line 26), your path for the "delete" icon does not take into account the base path. If Drupal is not installed in the site "root" but in a sub-folder, the icon will not show up. Fix:
With a call to base_path():
Or, even "nicer", allowing themes to more easily extend your templates:
In .module, hook_theme():
In .tpl.php:
I also see that you use variable_get() a lot, but you don't provide a default value. Usually that's not an issue, but I wonder about the emails you send in basic_cart.cart.inc: If the subject variable is not set, for example, it will be NULL. Depending on the mail configuration of the server (Microsoft IIS anyone ??), could this trigger an error ? Just to be safe, I would set a default value (just as with the 'basic_cart_content_types' variable I showed you before - documentation on variable_get()).Sorry, I see that you set default values in your .install file. My bad.Comment #4
alex dicianu commentedHmm, good point.
I thought about that, but I totally forgot :)
Fixed and commited.
Comment #5
alex dicianu commentedComment #6
alex dicianu commentedMade the changes. Please review :)
Thanks.
Comment #7
klausiIt appears you are working in the "master" branch in git. You should really be working in a version specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git.
Review of the master branch:
This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Go and review some other project applications, so we can get back to yours sooner.
manual review:
Comment #8
alex dicianu commentedOk, I fixed the code formatting issues. Now both the Coder module and the Drupal Code Sniffer module agree: "No Problems Found" :)
I also fixed the placeholder in variable_get, corrected the doc block, added the check_plain verification to sanitize the node type names before showing them and moved the code from the master branch to 7.x-1.x branch.
Regarding the part with the yet another shopping cart solution for Drupal, I don't agree with you. As far as I seen, in all the 14 000 existing modules, there are only two solutions like this in Drupal 7 (Ubercart and Ecommerce), both of them being very heavy in code and options. This is by any means a good thing, but if you just have a simple, small website with just a few things to sell, you won't need all these options.
Imagine your small website is just a showcase site. Let's say you are a photographer and you just publish your photos with a description, location, people present in the picture, etc and tomorrow you decide you want to sell them. With Ecommerce you have to import all the photos that have been entered as another content type. That requires a developer, you have to pay him, he needs time to do this, etc. With this module, you just enable the content type on the configuration page and the photos will be available right away.
This is just one example, there are many more ...
Comment #9
alex dicianu commentedMade the changes.
Please review :)
Comment #10
Niklas Fiekas commentedREADME.txt
images/delete.gif
basic_cart.module
basic_cart.cart.inc
basic_cart_cart_render.tpl.php
basic_cart.info
configure = admin/config/basic_cart/settings.All this is super minor and should probably not block this project from being promoted. Finally a security flaw:
<script>alert('xss!');</script>to a node body.Comment #11
alex dicianu commentedHi,
Thanks for your review. I fixed the issues you mentioned, removed the "7.x-1.0 dev release" text ... I'm not sure what I was thinking at the time :)
Comment #12
klausiFixing status.
Get a review bonus and we will come back to your application sooner.
Comment #13
alex dicianu commentedAdded review bonus tag.
Comment #14
klausiReview of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.
l('<img src="' . $base_path ...": you should use theme('image', ...) here.I'm removing the review bonus tag, feel free to do at least 3 more reviews of other projects for adding it again.
Comment #15
alex dicianu commentedHmm, ok I corrected the coding style issues for the css file.
I also used the system_settings_form, corrected the xss issue, implemented drupal_mail and used theme('image') instead of
<img src="...">.Regarding "$options[$node_type] = check_plain($type->name);", I can't use array_map because the array $node_types isn't a simple key => value, but a key => object array.
Comment #15.0
alex dicianu commentedReviews of other projects added
Comment #16
alex dicianu commentedAdded bonus tag.
Comment #17
klausiYou forgot to fix the CSS file. Also, please do not remove security tag, we may use it for statistics or to show examples of security issues.
Comment #18
alex dicianu commentedHi,
Sorry about the security tag, I'll leave it the way it is.
I think I fixed it already. Here is the PAReview report:
Review of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.
Source: http://ventral.org/pareview - PAReview.sh online service
Comment #19
alex dicianu commentedComment #20
klausiI think ventral.org is not up to date, please see my attachment in comment #14. CSS coding standards: http://drupal.org/node/302199
Comment #21
alex dicianu commentedModified the css file to respect the coding standards. Also ran the PAReview check.
Comment #22
klausimanual review:
Otherwise I think this is RTBC. Removing review bonus tag.
Comment #23
alex dicianu commentedUps!! I didn't saw that.
Fixed it.
Comment #24
elc commentedThere are few niggly bits, but I have included a question which I need answered before proceeding.
The menu items not having any permissions is a rather important one too.
configure = admin/config/basic_cart/settings.require_once drupal_get_path('module', 'basic_cart') . '/basic_cart.cart.inc';'page arguments' => array(3), the node will be auto-loaded for you and passed as a parameter. I can see how it might be an advantage to not load the entire node again for something that is already in the $_SESSION.Comment #25
alex dicianu commentedRemoved the dot from the .info settings config. It should work fine now. I also added the "access content" restriction to the cart, cart/add, cart/remove, checkout ... and used module_load_include instead of require_once php function.
Regarding your question, the answer is simple. As you can see in the screenshot attached, I wanted to display the cart with the quantity field x the node title with a node description just underneath and the remove from cart icon. Using the form api I couldn't find an obvious way to do this, so instead of letting drupal render the form, I rendered it myself.
I looked into the commerce module and I saw that there, the shopping cart is rendered using views. I find this a bit complicated for what I need.
Regarding the logic in the template file, there is nothing fancy, just 3
<?php if(!$is_checkout): ?>that show/hide the quantity field, remove from cart icon and the update/checkout buttons. I can avoid this by separating the cart and checkout functionality into 2 more or less identical templates, but I don't know if this would be an improvement.Waiting for your opinion ...
Comment #25.0
alex dicianu commentedadded 3 project reviews
Comment #26
elc commentedThe layout in the SS can be done with the Forms API. It's identical to a render array so things like tables, or nested divs can be done. I would highly recommend it as it shows proper use of the Drupal API.
As part of a normal form (completely untested)
You could keep the cart part of the array in its own function that gets pulled into the other two forms (cart view and checkout). Let me know if you have any questions about that.
re: "access content"; a local permission would allow site admins to set a sub-user who can do this. The check for permission should also go on the code that adds those links to the nodes.
re: module load include; embarrassingly enough, apparently using this function is not recommended when loading files from the same module. I had to go ask around after reading up on it as it seemed to be a bit undefined. Sorry bout that. But, it should include the DRUPAL_ROOT, or something that negates the need for it. Because it's conditionally included, "include_once" should be used. "require_once" is for unconditionally including files. Require drags the file in at compile time, include drags it in when physically encountered in the code. So, either
include_once dirname(__FILE__) . '/mymodule.foobar.inc';or
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'mymodule') . '/mymodule.inc';The former is probably faster. If you were loading another modules files, it would be done with module_load_include. Sorry about the confusion.
Comment #27
alex dicianu commentedHmm, I didn't thought about prefixing and suffixing the quantity field with the extra info I needed. I've done that and now I'm using the form api 100%. Thanks for the tip :)
I also added a local permission for the shopping cart and introduced some verifications for the add to cart button as well as for the block.
I also changed the function for that file inclusion, from module_load_include to include_once.
Comment #28
alex dicianu commentedChanging priority to major according to http://drupal.org/node/539608
Comment #28.0
alex dicianu commentedadded module review
Comment #29
alex dicianu commentedAdding review bonus.
Comment #30
klausiReview of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.
manual review:
Otherwise still RTBC for me. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #31
elc commentedIt looks like the HTML in the cart form might be my fault so I should probably go through it and propose something. The rather long and complex prefix/suffix should be offloaded to a theme function as they should only really be used for wrapping things in a single tag. The table like layout of the cart should probably be a '#type' = 'table'. Anyway, I need to play wiht this a bit to come up with a better suggestion as it seems I've just confused things.
Comment #31.0
elc commentedAdded 3 project reviews.
Comment #31.1
alex dicianu commentedMore project reviews
Comment #32
alex dicianu commentedOk, so as far as I seen, in this case there are 2 solutions, both with advantages and disadvantages.
Solution 1
Advantage: Usage of the Form API 100%.
Disadvantage: Loss of the theming capabilities. Theming will only be possible using the ids and classes.
Solution 2
Advantage: Robust theming.
Disadvantage: We have to trust the developer to manualy render all the form elements inside the theme function.
I can go either way, but honestly I prefer the prefix/suffix to favor security. The Form API is a great tool, but unfortunately is showing it's limits in this case
Comment #33
klausiCouldn't you use #theme or #theme_wrappers on the form element? http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.ht...
Comment #34
alex dicianu commentedHmm, I guess I was wrong ... The form API has no limits :)
I added a theme function to render the cart elements separately.
Comment #35
patrickd commentedSo let's get a little more picky ;)
all comments should end with . / ? / !
Send an email to the customer after an order is placedcheckbox only one mail will be send, but you're expecting always two mails to be send:You should check whether you're handling with the right block before you check the permission (otherwise the permission will be check for each block that is viewed -> not good for performance)
could be replaced with (I think)
module_load_include('inc', 'basic_cart', 'basic_cart.cart.inc')'cart/add/' . $nid. ''what's that empty string good for?when I got no content types I get a blank page - you should provide some help here
hmm, I think these are minor, so..
welcome to the community of project contributors on drupal.org and many thanks for your contribution!
I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
As you continue to work on your module, keep in mind: Commit messages - providing history and credit and Release naming conventions.
Thanks to the dedicated reviewer(s) as well.
Comment #36
alex dicianu commentedHi,
Thanks for your all your reviews, your patience and attention in examining my module.
I have done the necessary changes for most of the points you mentioned. I will try to implement the rest of them soon.
Thanks.
Comment #37.0
(not verified) commentedMore project reviews
Comment #38
AmalBK commentedI want to access the module variable basic cart (total price and quantity) and display them in another place how I can get an idea? Thank you.