Back to PhocacartCoupon class

Method storeCouponProductsById

public static
storeCouponProductsById
(mixed $itemString, mixed $couponId)

Method storeCouponProductsById - Source code

/*
public function checkCouponAdvanced($id, $catid) {


	if (!empty($this->coupon)) {

		$ids	= explode(',', $this->coupon['product']);
		$catids	= explode(',', $this->coupon['category']);

		// Products
		if(!empty($ids)) {
			if (in_array($id, $ids)) {
				return true;
			}
		}

		// Categories
		if(!empty($catids)) {
			if (in_array($catid, $catids)) {
				return true;
			}
		}

		// No condition regarding ids or catids was set, coupon is valid for every item
		if (empty($ids) && empty($catids)) {
			return true;
		}

		if (isset($ids[0]) && $ids[0] == '' && isset($catids[0]) && $catids[0] == '') {
			return true;
		}

		return false;
	}
	return false;
}

public function checkCouponTotal($amount, $totalAmount) {
	if (!empty($this->coupon)) {
		if ($amount > $totalAmount) {
			return true;
		}
		return false;
	}
	return false;
}
*/
/*
 * Static part
 */
public static function storeCouponProductsById($itemString, $couponId)
{
    if ((int) $couponId > 0) {
        $db = Factory::getDBO();
        $query = ' DELETE ' . ' FROM #__phocacart_coupon_products' . ' WHERE coupon_id = ' . (int) $couponId;
        $db->setQuery($query);
        $db->execute();
        if (isset($itemString) && $itemString != '') {
            $couponArray = explode(",", $itemString);
            $values = array();
            $valuesString = '';
            foreach ($couponArray as $k => $v) {
                $values[] = ' (' . (int) $couponId . ', ' . (int) $v . ')';
            }
            if (!empty($values)) {
                $valuesString = implode(',', $values);
                $query = ' INSERT INTO #__phocacart_coupon_products (coupon_id, product_id)' . ' VALUES ' . (string) $valuesString;
                $db->setQuery($query);
                $db->execute();
            }
        }
    }
}