Price Modification Based On Text Entry

Hi There,



Was trying to post this in the developer section but i don't seem to have forum permissions for that, basically I am attempting to do the following, I want toad an incremental value to a product based on the length of the text they enter, in this case it would be a name to be added to a product to customise it, there would be a variable charge based on how many letters were in the name, I am a novice PHP coder so I understand how to modify the values I need but getting the initial data and sending it back to cscart is a little beyond me, is there already an addon to do this or if someone could explain what variables I would need to hook in to to modify the array before its added to the cart that would be great.



Again apologies for this being In the wrong section

Well I have created an addon that I “think” will do what I want but the issue is it wont install, the install button is there and when I click it I see the loading spinner very briefly and nothing happens, no error message and the addon isn't installed, there are no error logs anywhere

I have resolved the installation issue I was having, it seems there was an error in my section so I’ve opted to just hardcode the values, I “think” my problem is with how its being hooked, the code never seems to run (I have some test code to generate a file to see if its run) but the addon does seem to interact in some way as when its active I can’t add any items to the cart, when I disable it I suddenly get multiple cart items appear, any help with this is appreciated although I would prefer advice instead of “We can fix this for $x” as I’m more interested in learning how to get addons to work properly for future projects :)



As such 'm not expecting anyone to dig through my code for me I’m just looking for any tutorials other beginner addon creators might have used other than the 2 examples on the CS Cart site

An update, I've managed to get the addon to load and to access data, I have $cart but my problem I that the array doesn't seem to have the descriptions for the product options which has kinda thrown a hammer in the works which makes processing multiple items more annoying as the “global option” ID isn't infact globally shared it just makes a copy of the option for each item, I “could” do a DB lookup on every single option ID to try and match it but that seems messy, is there a way to just access the description string for the option without complicating code

Not sure what you mean by "complicating code'. If you need the option name/description then you'll have to do a lookup ased on the option_id/variant_id of the option in question.

"Not sure what you mean by “complicating code'. If you need the option name/description then you'll have to do a lookup ased on the option_id/variant_id of the option in question.”



Yeah thats what I figured, and by complicating I meant having to do more lookups than is required, I already noticed that the tiny part of code I added to dump a few vars added a very noticeable lag to adding items to the cart so I was hoping those descriptions were already in vars somewhere that I could just reference instead, well no worries I'll have to mess around with some DB queries when I take another look at it in the morning, thanks for the help so far though

Descriptions are there on the GET but not needed or wanted on the POST. So if you've hooked into the POST, they will not be there. and they are NEVER in the $_SESSION['cart'].



You shouldn't see a lag after the 1st execution since you are probably rebuilding the cache after your changes.

Well I’ve sorted out pulling the option descriptions and wrote the code the calculate how much needs to be added and modified the value in $cart, the issue is that it doesn’t seem to be sticking, is there a function to force it to recalculate the price before adding the item to the cart, I’m hooking in to add_to_cart and I’ve looked at both pre_ and post_ but those don’t seem to contain the actual item being added to the cart, I can provide my code if it helps, I should point out I am accessing $cart by reference with &



Any advice is greatly appreciated :)

Look at the function fn_add_item_to_cart() (or similar name) in fn.cart.php

You will probably have to call fn_calculate_cart() and you may need to add a hook for 'calculate_cart' in order to run your custom stuff each time the cart is recalculated. Depends on what/how you've done your custom code.