public function getUsagesLeft($customerId = null)
    {
        $usageLeft = $this->getMaxUsage();

        if ($this->getPerCustomerUsageCount()) {
            // Get usage left for current customer. If the record is not found,
            // it means that the customer has not yes used this coupon.
            if (null !== $couponCustomerCount = CouponCustomerCountQuery::create()
                    ->filterByCouponId($this->getId())
                    ->filterByCustomerId($customerId)
                    ->findOne()) {
                // The coupon has already been used -> remove this customer's usage count
                $usageLeft -= $couponCustomerCount->getCount();
            }
        }

        return $usageLeft;
    }
public function getUsagesLeft($customerId = null)
    {
        $usageLeft = $this->getMaxUsage();

        if ($this->getPerCustomerUsageCount()) {
            // Get usage left for current customer. If the record is not found,
            // it means that the customer has not yes used this coupon.
            if (null !== $couponCustomerCount = CouponCustomerCountQuery::create()
                    ->filterByCouponId($this->getId())
                    ->filterByCustomerId($customerId)
                    ->findOne()) {
                // The coupon has already been used -> remove this customer's usage count
                $usageLeft -= $couponCustomerCount->getCount();
            }
        }

        return $usageLeft;
    }
public function getUsagesLeft ( $ customerId = null ) { $ usageLeft = $ this -> getMaxUsage ( ) ; if ( $ this -> getPerCustomerUsageCount ( ) ) { // Get usage left for current customer. If the record is not found, // it means that the customer has not yes used this coupon. if ( null !== $ couponCustomerCount = CouponCustomerCountQuery :: create ( ) -> filterByCouponId ( $ this -> getId ( ) ) -> filterByCustomerId ( $ customerId ) -> findOne ( ) ) { // The coupon has already been used -> remove this customer's usage count $ usageLeft -= $ couponCustomerCount -> getCount ( ) ; } } return $ usageLeft ; }
Get coupon usage left, either overall, or per customer.

@param int|null $customerId the ID of the ordering customer

@return int the usage left.
Get coupon usage left either overall or per customer .