CD Implementation

HomeSupportImage StoreCD Implementation

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #55515
    lch503
    Participant

    Hello,

    I have started the re-write of the CD Discount implementation that I sent to you a couple of weeks ago so that I just have to add one file rather than modifying admin files etc.

    I plan to have this additional file stored in a subfolder cd in the _inc folder, and the file called cd.php

    The one thing I have not got my head around in php is classes, and was hoping you could assist. Is it the same as classes in object-orientated languages such as Java?

    When adding sagePay.php and therefore the class this was easy because I just added it to the list of payment gateways.

    I know I need to add code somewhere in image store to let it know that my cd.php file is there, and use its class. Where do you think this would be best?

    Remember, I need to change the appearance of pricing.php so that there is an additional tab for cd discounts, and I need to change cart.php so that the customer cannot change quantities etc.

    Therefore, I presume this must be high in the class hierarchy.

    Thanks,

    Leon

    #55526
    Xpark Media
    Keymaster

    @lch503,

    Don’t add any files in the image-store directory, create a new plugin that uses the image store hooks.

    The classes are similar to java, but the syntax is different. You can create your own class in your new plugin and interact with the global $ImStore and $ImStoreCart objects while using the hooks.

    You can also create many instances of the object by using $my_variable = new ClasName();  but we recommend that you interact with the global variables already created.

    We have attached a few files to get you started with the new plugin.

    #55542
    lch503
    Participant

    Thank you very much.

    This has really helped me get started.

    Leon

    #55545
    lch503
    Participant

    Hello,

    I am getting quite far in my implementation of the CD plugin, however I am having some issues I think mainly due my understanding.

    I have performed all the administration side that I require so rather than changing the core plugin, I have made an extra tab appear in pricing discounts on CDs, added a meta box for adding a discount and removing discounts.

    I have even added a few things such as the extension will not activate unless the image-store plugin is activated, as well as removing all discounts from the wordpress database upon uninstallation of the core plugin.

    I am having issues with the customer side.

    I have to be able to:

      If the customer tries to add more than one of the same CD image, let them know with an error and reduce the quantity to 1. (This makes sense as only one of the same image will be on a CD)
      Add the discounts and manipulate the total price accordingly

    The basic problem I am having is changing the values of the cart from my extension plugin.

    There are plenty of do_action() hooks to use, and there are some in the right place. The problem I am having is changing the values of the cart, such as quantity of the CD images, the total value of the cart etc. from my extension plugin.

    Can you help?

    Thanks,

    Leon

    #55554
    lch503
    Participant

    I am getting there now.

    I can now change values in the cart from my extension.

    Of all the hooks, I think before_save_cart is the best to use as in both before_add_to_cart and before_update_cart change the values that I change in my extension, therefore my changes are overwritten.

    At the moment I am working with the quantity value. I change this with the before_save_cart hook, however, I must update the cart to see my changes. A simple refresh of the page does not work, and I cant call update_cart from my extension as I get an infinite loop (as it is called again from the same before_save_cart hook).

    I am going to think about this, but any insight would be greatly appreciated.

    Thanks,

    Leon

    #55564
    Xpark Media
    Keymaster

    @lch503,

    You could use “ims_after_add_to_cart” or “ims_before_save_cart”,

    if you use “ims_after_add_to_cart” all processing by image store is completed and saved and you will have to modify the data and save it back again to the database using “update_post_meta( $orderid, ‘_ims_order_data’, $this->cart );”

    There other hooks base on specific cart actions

    ims_before_save_cart_{$action}
    ims_after_add_to_cart_{$action}

    #55592
    lch503
    Participant

    Hello,

    I am getting quite far now. I am working on the front end.

    If the customer chooses a CD option and requests more than one of the same image on a CD I have implemented an error system where the image store throws an error “invalid cd quantity” and resets the quantity to 1.

    This is implemented in the before_save_cart hook.

    This is working for the most part, however sometimes the error is seen as:

    “Successfully added to cartInvalid CD quantity”

    In the popover. This is shown with a green background rather than red as an error usually does. If I try again the error is thrown correctly.

    After some debugging I have narrowed it down to the expiry of the cookie set on line 566 in the add_to_cart() function of _inc/store.php. The line is setcookie(‘ims_message’)… If I set it to time() + 2 I don’t see the incorrect error. This is bad on my part because I am modifying your code.

    Is there a correct hook I can use to unset the cookie before the message is displayed, or if not could you please create one in your next release?

    Could you supply the correct code for invalidating this cookie correctly?

    Note that there is also a setcookie(‘ims_message’)… line of code on line 591 in the update_cart() function in _inc/store.php if you need to add a hook.

    Thanks,

    Leon

    #55598
    Xpark Media
    Keymaster

    How are you setting the error? what you want to do is overwrite the error message, when the cart is updated and there is an error. The plugin will do all the work.

    $ImStore->message = false;
    $ImStore->error ="Error message"
    #55603
    lch503
    Participant

    my function linking the before_save_cart hook is:

    
    function cd_in_cart( ){
    			global $ImStoreCart;
    			
    			if ( $ImStoreCart->cart['cderror'] = 1 ){
    				$ImStoreCart->cart['cderror'] = 0;
    			}
    			
    			$cart = $ImStoreCart->cart['images'];
    			foreach ( $cart as $id => $sizes ){
    				foreach ( $sizes as $size => $colors ) {
    					foreach ( $colors as $color => $values ) {
    						if ($cart[$id][$size][$color]['size'] = "CD"){
    							if ($ImStoreCart->cart['images'][$id][$size][$color]['quantity'] > 1){
    $ImStoreCart->cart['cderror'] = 1;
    								$ImStoreCart->cart['images'][$id][$size][$color]['quantity'] = 1;
    								$ImStoreCart->error = __( 'Error in CD Quantity', 'ims' );
    	}
    						}
    					}
    				}
    			}
    			
    		}
    }

    I find that if I use global $ImStore in this function I don’t have access to the $ImStore variables, but I do with the $ImStoreCart variables, hence I use that.

    I cannot therefore do as you suggest and falsify the $ImStore message variable. I have tried your suggestion and unfortunately this does not work.

    Thanks,

    Leon

    #55608
    lch503
    Participant

    I think this is because the before_save_cart hook passes the cart, and not the store itself. Therefore I do not have access to the global $ImStore variables, only the cart.

    #55610
    lch503
    Participant

    Hello,

    I have managed to implement the change in the cookie without changing your code (its all done in the extension)

    Using before_post_actions I have implemented my own add_to_cart() method that is exactly the same as seen in _inc/store.php apart from changing the cookie expiry to time()+2.

    Thanks!

    Leon

    #55612
    Xpark Media
    Keymaster

    @lch503,

    We are glad that you were able to find a solution, for future references, in your function you call the global objec $ImStoreCart in the same way you can get access to $ImStore.

    global $ImStoreCart, $ImStore; 
    #55973
    lch503
    Participant

    Hello,

    I have completed the CD plugin.

    You can mark this as closed.

    Thanks,

    Leon

    #56730
    CJsFotos
    Participant

    I would like to add the CD option, is there a place I may download the add-in?

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.