Shop Donation

Author Message

David Jones

Thursday 28 September 2006 4:12:28 am

I want to add a product to my shop for a donation.

ie. one where the user can input the price.

Is this possible?

Paul Forsyth

Thursday 28 September 2006 7:02:10 am

Yip, its possible but you need to patch a couple of files to pass through your donation value.

How comfortable are you with patching the eZ kernel files?

Paul

Claudia Kosny

Thursday 28 September 2006 1:16:13 pm

Hi Paul

I would be very comfortable with patching kernel files (actually I do it to often instead of creating extensions...) So if you would give me some hints it would be very appreciated as I want to something similar to what David wants to do.

Thanks in advance

Claudia

David Jones

Tuesday 23 January 2007 5:21:36 am

Claudia,

Did you work out how to do this?

David Jones

Thursday 25 January 2007 11:27:17 pm

Anyone?

kracker (the)

Friday 26 January 2007 12:17:21 am

When I needed to modify the shop checkout,
similar to way you describe. I found I needed
to modify these files.

kernel/shop/add.php
kernel/shop/ezshopoperationcollection.php

In the file, 'kernel/shop/add.php'
See the contents of the file, <i>Do you see ...</i>

// Check if the object has a price datatype, if not it cannot be used in the basket
$error = $basket->canAddProduct( $object );
if ( $error !== EZ_ERROR_SHOP_OK )
    return $Module->handleError( $error, 'shop' );

In the file, 'kernel/shop/ezshopoperationcollection.php'
See the contents of the function, 'addToBasket', <i>Do you see ...</i>

    function addToBasket( $objectID, $optionList )
    {
        include_once( 'kernel/shop/classes/ezshopfunctions.php' );
                $http =& eZHTTPTool::instance();
        
        $object = eZContentObject::fetch( $objectID );
        $nodeID = $object->attribute( 'main_node_id' );
        $price = 0.0;
        $isVATIncluded = true;
        $attributes = $object->contentObjectAttributes();

        $priceFound = false;

        foreach ( $attributes as $attribute )
        {
            $dataType = $attribute->dataType();
            if ( eZShopFunctions::isProductDatatype( $dataType->isA() ) )
            {
                $priceObj =& $attribute->content();
                $price += $priceObj->attribute( 'price' );
                $priceFound = true;
            }
        }

        if ( !$priceFound )

<i>Do you see ...</i>
This is not a solution. I don't need this atm. Still I have noted this thread for future reference.
This is me telling you your not trying hard enough to find any solutions on your own because
I did this simply by reading the documentation and source code for related keywords.....

Still a user with even marginal skill should be able to see how to pass a form text input variable (user defined price) to the related part of the kernel (above) and use this additional input as the product 'price'.

<i>//kracker
If your not a programmer you may wish to make friends with one ;P

Garbage - The World Is Not Enough</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

David Jones

Friday 26 January 2007 6:39:33 am

kracker, I'm sorry if my ignorance is an offence to you.

I do however appreciate your help.

I had, actually got as far as working out that I need to pass it a new variable. You really don't need to be a programmer to work that out.

However, this is something I do no know how to do.

If anybody could offer assistance I would be most grateful.

Rob Borley

Tuesday 13 February 2007 3:37:51 am

David, This isn't a straight forward as Kracker wants to make out (as the lack of response to this post only shows). Or at least, if it is I've missed the point and would really appreciate his knowledge.

I decided that the approach to take was to create a new DataType and then allow the addToBasket function to use it.

However, I couldn't work out how to do that.

So I decided to use the ezinteger as I'm not using it in any other classes.

The code for the addToBasket function i ended up with was as follows

 foreach ( $attributes as $attribute )
        {
            $dataType = $attribute->dataType();
            if ( eZShopFunctions::isProductDatatype( $dataType->isA() ) )
            {
                $priceObj =& $attribute->content();
                //$price += $priceObj->attribute( 'price' );
                //$priceFound = true;
                
                			if (array_key_exists('price', $priceObj)) {
 						$price += $priceObj('price');
 						$priceFound = true;
					} elseif (array_key_exists('integer', $priceObj)){
  						$price += $priceObj('integer');
  						$priceFound = true;
					} else {
					$priceFound = false;
					
					}
                
                
            }

I got this far and realised that attribute is actually a function and so the debug is returning the following error.

array_key_exists(): The second argument should be either an array or an object in

So I thought I'd dig out the attribute function and have a hack around with that.

Only problem is I can't find it!!!!

Please, somebody, anybody, put me out of my misery.

kracker (the)

Tuesday 13 February 2007 1:18:21 pm

oh so quickly the anger courses as it flows through the ignorant but self aware just enough to grasp beyond the pattern of behavior which binds to blind them never giving out enough to cowardly begging for answers not earned. na, I don't understand myself either what was I thinking at even coming this far without falling through time into the other side so soundly and silently with an attitude of defiance to the armies gathering against those who value their own without betraying those without completely. i got bored and ran with it when I slowed down, I realized I was here, left wonder what it ment to me.

Aliases and Icons coming back with another realms in vengeance. So quick to so solely donate blame or responsibility to the-others who give you directions for going silently into the night in guilty innocent ignorance. I laugh at the neverlast, the mindset from pro to post eZ and the different misdirections they travel on afterwards.

You never needed anything more than the code, Wouldn't trade the wealth, You wouldn't if you had what you wanted in the first place, I'd rather, respect mine, than blather, so badly follow inline. I got the life and it's one life one love and who's who in my family. I hate that I see it in what I read so clearly. The stupid way we all are to avoid to become to avoid to accept to move on to improve without realizing you did the work yourself to avoid the knowledge of how to save your self.

The game is more than points. You really don't need to hate me. I was like you (I't relates relatively speaking who?)
You could end up like all the rest who came and gone if you don't break on through to the otherside. Cheer up *tch, you'll get it or it will destroy you attitude.

Neva stop trying, Live your own life. Remember your roots, live for yourself, not to fulfill the desires of others. This is a wake up layover half track pushed simply to remind yourself to wake up or go back to sleep. Wait who am I talking too?

<i>//kracker
yeah it's a drop to a bleak beat but you can't feel your pulse either ...</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Rob Borley

Tuesday 13 February 2007 1:36:24 pm

Very poetic...

Any idea what I'm supposed to do next?

Bruce Morrison

Tuesday 13 February 2007 3:28:40 pm

Hi David & Rob

I've got to implement something similar shortly. I'm yet to spend a lot of time working on a solution as we've only just finishing off the spec.

Due to the inherent issues with modifying the eZ publish core I'm looking at solutions that can be accomplished without these changes.

What I'm going to try is creating a donation content class that consists of a price attribute and allowing users to add content objects of this class. An after publish workflow would then add the newly published donation to the current users cart where is would be processed as any other product.

What do you think?

Cheers
Bruce

@kracker
I'm sure you've heard of the saying - <i>"if you're not part of the solution you're part of the problem"</i>. In this instance you are part of the problem.

All you have achieved with that post is to pollute the forums with 382 words that do nothing to help solve the problem and increase eZ publish knowledge. I'm not sure how this fits with your philosophy that <i>"no one gets left behind or forgotten"</i> or your continual posts encouraging people to contribute solutions.

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

/dev/null

Tuesday 13 February 2007 4:45:50 pm

Could you control quantity of a content object added to cart as one way to control subtotal price of order item?

Or does the kernel support a way to affect the value fetched for item price alone in a dynamic passed form variable way during the adding of a content object of class 'product' during add to basket (as the rest of the order system will use this price).

I read once ezoption could provide for simple options in this way, but a predefined list might not work for a donation product or would it ....

If your option was price which was in addition to a default product price of 0.00.
If you have option items in increments say 1,000$ to 100,000$ then the user can chose which increment for their donation.

You might want to place a disclaimer or other text instructing the user how to use the system right above the ezoption's display perhaps with the description attribute or a separate disclaimer description attribute.

It seems like a form to provide an unknown user the ability to submit any numeric number might not be as desired as you first think. A predefined list controls the bare minimum allowed and provides for increments from small to way to much. Controlled input seem like it would simply avoid what bruce describes, even though his idea prolly provides the greater set of functionality with the least amount of problems through an upgrade.

<i>/dev/null</i>

eZpedia community documentation project: http://ezpedia.org

Bruce Morrison

Tuesday 13 February 2007 5:14:39 pm

Thanks for the feedback /dev/null. I hadn't considered the issue of quantities. I'm not sure it's a big issue as users would have to actually increase the quantities themselves - i.e. make a conscious decision to donate more.

With ezoption data type you can set additional prices
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/datatypes/option
This could be used as you describe to create a predefined list of donations options. Our client wants this <b>and</b> the ability to do arbitrary donations as well as selling products.

Other less thought out solutions I've had involve creating a module that collects the donation value and stores it in the session. Workflow would be added to the shop to add this to the "basket" in much the same was that shipping handlers work.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

/dev/null

Tuesday 13 February 2007 10:00:48 pm

No worries Bruce,

That's an interesting notion you describe. It may not be as direct of an implementation (or is it ...) as one might desire, it sure seems functional without incurring a kernel modification.

<i>/dev/null</i>

eZpedia community documentation project: http://ezpedia.org

Rob Borley

Tuesday 13 February 2007 11:34:37 pm

Thanks guys, that is constructive.

I'm calling the predefined options route plan 'b'

My client wants the user to enter their donation into a form field. If they choose to donate 50p then they can. :o)

Your right though, hacking the kernal is proving to be less than straight forward.

Paul, at the top of this post, suggested he might have a solution. I'd be interested to hear what he has to say.

Rob

/dev/null

Wednesday 14 February 2007 5:00:57 am

I still think that there are a few conclusions you can make on this subject from this thread alone.

Still before I do I wanted to take it back for just a moment to point out that, The approach 'Rob' made was interesting in that he was trying to use a custom datatype in his product class which instead of providing a price from the content structure attribute providing a price from the form input submitted during the request.

So how many different ways were discussed here?
- Using a workflow event and trigger to set the price summited by a user via $_POST variables during add to basket.
- Using a custom datatype to use the submitted price instead during the add to basket usage.
- Adding user permissions to create an instance of a class and update of a the object attribute transparently to the user (useful for complex product creation from other products)
- Kernel Patch (of various types)

Did I miss one? Sounds a lot like no right or wrong answer on how to set the price more of where to insert an override to support the submission and storage of the information with a lot of options at every turn. More of a what meets my needs, what do I know how to do, how can I bridge the gap, where can I follow the data through the layers to point x in the code to insert value y using custom instance z an all the validation and error handling just in case too.

fun..
<i>/dev/null</i>

eZpedia community documentation project: http://ezpedia.org

kracker (the)

Wednesday 14 February 2007 5:44:19 am

Stub node added to eZpedia,
http://ezpedia.org/wiki/en/ez/donation

Content encouraged, sold-iers enabled,
Imagine it's like writing and it makes it easier.
{'Insert randomly generated quip or remark here'|limit($7x)}
I'm not joking but I'll laugh just the same.

float on,
//kracker

Haiku de' Tat (Aceyalone, Mikah 9, Abstract Rude) - Wants vs. Needs
<i>http://www.lyricsdir.com/haiku-detat-wants-vs-needs-lyrics.html</i>
Now... Ludacris (Disturbin' the peace) - Roll Out (My Business) (Instrumental)

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Claudia Kosny

Wednesday 14 February 2007 2:43:01 pm

Hi there

Here just my 2c:
I have given up to patch the shop files for an custom set price. Whereas it was pretty easy to pass the custom price through to the addToBasket function, I did not find a good solution for viewing the basket later on as updatePrices is always called, which fetches the price again from the contentobject. Also using a wishlist would have caused problems.
I have then written a extension which creates a donation object each time a user wants to donate something and then redirects to the shop module. The objects are reused if someone donates the same amount. This works quite well, especially since you do not have to patch any files at all.
At the end I decided that I would rather not clutter up my installation with potentially dozens of donation objects so I just offer a choice of a few preset amounts.

@dev/null
The problem I see with using a trigger is again the updateprices() function. As the post data is not there anymore when this is called, we have a problem.Maybe one could get around that by storing the custom prices somewhere permanently and adapting the functions accordingly.

@Rob Borley
Seeing what's wrong with your code is pretty hard without further explanations. In the part of code you posted I see two strange things, which do not seem to be related to the error message however.
You use $priceObj('price') which should not work, as $priceObject is an object, not a function. You can access the attribute price of the object using $priceObj ->attribute('price').
I am also wondering about where the $priceObj('integer') is coming from. Assuming you have made the same mistake as above, you want to access the 'integer' attribute of the priceobject. Afaik it does not have such an attribute at all. If $priceObj is an instance of your new datatype, this attribute might of course be there, but without more info about the datatype this is hard to say.
So if you still need some help, post a bit info about what your datatype looks like and what exactly it is supposed to do.

Claudia

Bruce Morrison

Wednesday 14 February 2007 5:21:20 pm

Hi All

I've looked into how the shop handles prices and I think that with the right datatype and some very minor core changes you could utilise the custom datatype method.

The first step would be to add your datatype to the array in eZShopFunctions::productDatatypeStringList
http://pubsvn.ez.no/nextgen/trunk/kernel/shop/classes/ezshopfunctions.php

To make things more flexible these values could be moved to the shop.ini

You would then have to craft the datatype to use the options mechanism provided by the ezOption datatype (and used throughout the shop code) to collect an arbitrary value.

@/dev/null
To clarify your list, any custom datatype solution would require kernel changes as the kernel currently deals with a static list of datatypes for pricing.

The list so far as I see it is:
a) Custom datatype & kernel mods
b) Collecting donation amount, storing in session and adding via workflow at checkout time (like shipping)
c) Allow users to create donation "content class" and add to basket as regular product (possible quantity issue)

I've dropped any major kernel mods from the list as you'd be pretty much one your own with support.

@Claudia
It looks like you have solved c) quite nicely. Any chance of adding it as a contribution?

The problem I see with using a trigger is again the updateprices() function. As the post data is not there anymore when this is called, we have a problem.Maybe one could get around that by storing the custom prices somewhere permanently and adapting the functions accordingly.

The value could be stored in the session. I haven't done any major work with the shop for a while so I not sure just how the shipping workflow and the workflow to add this functionality would fit in.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Rob Borley

Thursday 15 February 2007 12:29:18 am

Hi Claudia,

I still am very much interested in a solution.

I went for plan B in the end. Just because I need to have something working now.

As for my code above, sorry if it's confusing.

I was using a custom class, which I used an integer as an input just to rule out that it was my data type that was causing the problem.

Then I realised that attribute was function (it took a while as it was a long night of banging my head against a brick wall. *smile*)

So i wanted to track down this function so I could work out what it was doing and therefore what I need to do with my data type; if that makes any sense.

But I simply couldn't find it.

Hope that clears that up. I will be having another bash soon (when under less time pressure) at getting this to work and so will follow this thread with interest. It reassuring to know that I am not the only one who has struggled with this problem.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.