I’m building a site with the SCM and would like to have a saef that will automatically add the weblog entry to the store.
This was mentioned in this thread: Chilling out with Simple Commerce
I was wondering, would an extension be good for this? Has anyone done that already?
I can’t share the code with you, but I tought I’d let you know that you’re on the right track. An EXT for the SAEF is all you need. One that adds an SC item on successful SAEF submit. I wrote one just like that when building the JobsAndGigs.com custom code for Luke Stevens, so I know for a fact it will work.
Good luck!
Hi both!! 😊,
I just came across this thread and this functionality would be absolutely spot on for a site that I am currently developing. I envisage the site having well over 10,000 products in it and this will definitely go up in the future. I was wondering if either of you would be prepared to let us all know how this can be done or if you don’t want us to see your code I was wondering if you would possibly talk me and others here through how to actually use a hook in an extension as I have looked at the developer documents on this site and have tried pulling apart a simple extension but my PHP skills are not that good and I don’t really understand enough of it and also the way EE works internally to be able to pull off these kinds of extensions although I would love to be able to do so as then I could give even more back to the EE community than I do now (hopefully I am giving back at the moment anyway! 😊 )
Just some help or general push in the right direction as to how to use hooks would be great and maybe in this case which hook to use?
Any help with this would be massively appreciated and not just by myself I imagine but probably many of the users on these forums too.
Thanks again.
Best wishes,
Mark
Hey Mark, this was actually super simple. I’ve never written an extension before and it only took a little bit to figure out. My php skills are pretty basic as well.
What I did was use the exp_simple_commerce_items hook and check if a variable that I put on the front end “Add Product to Store” form was there. If it was I then added an entry to the exp_simple_commerce_items table. I took all of like 6 lines. pretty simple.
Hi Jez,
Thanks for the reply. Just took a look at this page here but all I could find were these hooks listed. Are there more than that then as you mentioned an exp_simple_commerce_items hook?
simple_commerce_evaluate_ipn_response - (mod.simple_commerce.php) simple_commerce_perform_actions_end - (mod.simple_commerce.php) simple_commerce_perform_actions_start - (mod.simple_commerc.php)
To tell the truth though even though you say that you managed to do this in six lines I think I would have a lot of trouble figuring out what those six lines would need to be!! 😊
I have made a couple of very simple plug-ins before and I did make one extension but this didn’t use any hooks at all and I wouldn’t know where to start with it unfortunately.
I don’t suppose you would be able to push me in the right direction perhaps or maybe even just tell me where I can find some documentation on actually how to use the hooks?
Any help would be massively appreciated as I would love to learn how to write extensions so that I can help out others but my PHP skills are exceptionally limited I’m afraid.
Thanks again.
Best wishes,
Mark
exp_simple_commerce_items is a table in the database that SCM adds. It says which weblog entries should be store items.
I could post my code, I don’t mind, as long as expresionengineer is ok with that, he didn’t write any of it, but he pointed me in the right direction 😊 I’m not sure of “rules” about these things around here… maybe if someone can let me know if it’s cool to post it.
Well I won’t tell if you don’t!! 😊
Seriously though I hope someone can perhaps let us know what the situation with this kind of code sharing is as I would love to learn from this extension.
Actually thinking about it some more I may need more of a solution as each item will have a different price so would need some way of doing that. Perhaps an extension could be made so that once the entry is submitted it creates the new Simple Commerce item and then takes you to it so that you can fill out the prices?
Anyway if you can show me the code then it would be greatly appreciated as I would love to learn more about creating extensions but maybe what you have at the moment won’t do exactly what I need but I would still love to see it if I am allowed for a learning experience.
Maybe one of the EE admin crew could let us know about the legality on this kind of thing?
Thanks again.
Best wishes,
Mark
This part I wrote, so I figure I should be able to post it. It was specific to my need, so I hope you can get something from it.
function add_to_store( $entry_id, $data )
{
global $FNS;
if ($_POST['add_to_store_switch']=='y'){
$add_to_store_price = $_POST['price'];
$add_to_store_query = "INSERT INTO exp_simple_commerce_items (entry_id, item_enabled, item_regular_price, item_sale_price) VALUES ('$entry_id', 'y', '$add_to_store_price', '$add_to_store_price')";
mysql_query($add_to_store_query );
}
$EXT->end_script = TRUE;
}
I added a hidden field named “add_to_store_switch” with a value of “y” to my saef so I know that it was submitted from the add product form.
Then, I had a text input field for the price. I inserted this price right to the database on the SCM items table. That’s about as clearly as I can spell it out. If someone wants to make a full out extension from this that would be nice! As it’s my first try and I don’t even know what the global $FNS does, I don’t think I should be the one to write it for others!
Hiya,
Thanks for posting that. I will take a look at this in the next couple of days and try to wrap my head around it!! 😊
So you are using this with a SAEF? I thought that perhaps it was used in the Publish tab and once an entry had been submitted then it put a new SCM item in. Never-mind, I will take a look at this though as it may help my very small brain to figure out how exactly to code extensions so thanks for the information.
Hope you are having a good day.
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.