Skip to main content

custom plugin that activates when coupon deleted

More
11 years 5 months ago #199653 by diesel1984
-- HikaShop version -- : 2.3.1
-- Joomla version -- : 2.5.2
-- PHP version -- : 5

Hi,

I am trying to write a plugin that executes when a coupon is deleted from the frontend of the website by a customer. What i need it to do, is remove a particular item from the basket when a certain coupon is deleted. I have added what i have coded so far below. I cannot even get an exit() statement alone to execute in the onAfterDiscountDelete(&$elements) function. The onAfterDiscountDelete(&$elements) function doesn't appear to execute even when a coupon is deleted from the frontend of the website. I have written numerous plugins for hikashop now and they have all worked so far (except for this one)...

So i need to know:

Why my plugin is not executing;
What code i need to delete an item from the basket;

My plugin is installed and it is published so that is not the issue here. I have stored my plugin in:-

/plugins/hikashop/discount/

and that folder contains the following files:-
discount.php
discount.xml
index.html


The code below is contained within:-

/plugins/hikashop/discount/discount.php

Code:
<?php defined('_JEXEC') or die('Restricted access'); ?><?php class plgHikashopDiscount extends JPlugin { function plgHikashopDiscount(&$subject, $config) { parent::__construct($subject, $config); } function onAfterDiscountDelete(&$elements) { if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; } $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(); $numberOfProductsInCart = sizeof($cart->products); for($i=0; $i<$numberOfProductsInCart; $i++) { if($cart->products[$i] == 120) { //I need some code to remove this item from the basket - but what code will achieve that? } } } } ?>

Thanks in advance guys!

Please Log in or Create an account to join the conversation.

More
11 years 5 months ago #199663 by Jerome
Hi,

www.hikashop.com/support/support/documen...tation.html#discount

onAfterDiscountDelete( & $elements )
This function will be triggered by HikaShop after discounts/coupons are deleted, $elements is an array with a list of discount/coupon ids.


I'm sorry but the trigger you're using is not when a customer remove a coupon code in his checkout ; it's when a discount is delete from the database.

You should take a look at the trigger "onBeforeCouponLoad(&$coupon,&$do)" instead.

Regards,

Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Please Log in or Create an account to join the conversation.

Time to create page: 0.166 seconds
Powered by Kunena Forum