Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

  • 0
movieseals

Parameter must be an array or an object that implements Countable warning

Question

I would normally use the TB Stripe module but I need a subscription function for the magazines we sell.  I have a Stripe module that enables that but since switching to PHP 7.3, I get the following error in my php error log:

count(): Parameter must be an array or an object that implements Countable in /home/zbookstore/public_html/modules/stripepro/stripepro.php on line 410

Here is the code on and around line 410, where line 410 is in red:

 /**
     * [hookHeader => change add to cart button with subscribe button on home page as well as on product page]
     * @param  [type] $params [array containing information of the product]
     * @return [type]         [description]
     */
    public function hookHeader($params)
    {
                
        if (Tools::getValue('controller') == 'product')
        {
            $product_id = Tools::getValue('id_product');
            if(!empty($product_id))
            {
                $sub = Db::getInstance()->getValue('select `id_subscription_product` from `'._DB_PREFIX_.'stripepro_products` where `active` = 1 && `id_product_attribute`=0 && `id_product`= '.$product_id);
                if($sub != '')
                {
                    $this->context->smarty->assign('controller','product');
                    return $this->display(__FILE__, 'subscribe.tpl');
                }
            }
        }
        else
        {
            /* Continue only if we are in the checkout process */
            if (Tools::getValue('controller') != 'order-opc' && (!($_SERVER['PHP_SELF'] == __PS_BASE_URI__.'order.php' || $_SERVER['PHP_SELF'] == __PS_BASE_URI__.'order-opc.php' || Tools::getValue('controller') == 'order' || Tools::getValue('controller') == 'orderopc' || Tools::getValue('step') == 3 || Tools::getValue('controller') == 'supercheckout' || Tools::getValue('pm') == 'stripepro'))){
                
                $subscribe_products = Db::getInstance()->executeS('select * from `'._DB_PREFIX_.'stripepro_products`  where `active`= 1 && `id_product_attribute`=0 ');
                if (count($subscribe_products > 0))
                {
                    $this->context->smarty->assign('subscriptions',$subscribe_products);
                    return $this->display(__FILE__, 'subscribe.tpl');
                }
            
            } else {
                
                $nbProducts = $this->context->cart->nbProducts();
                if ($nbProducts<=0)
                   return;
      
                $this->smarty->assign($this->getPaymentVars());
                $this->context->controller->addCSS($this->_path.'views/css/stripe-prestashop.css');
                $this->context->controller->addJS("https://js.stripe.com/v2/");
                $this->context->controller->addJS("https://js.stripe.com/v3/");
        
                if(Configuration::get('STRIPE_CHKOUT_POPUP') || Configuration::get('STRIPE_ALLOW_BTC'))
                   $this->context->controller->addJS("https://checkout.stripe.com/checkout.js");
                   
                return $this->display(__FILE__, './views/templates/front/vars_payment.tpl');
            }
        }
    }
    
    public function checkCurrency($cart)
    {
        $currency_order = new Currency($cart->id_currency);
        $currencies_module = $this->getCurrency($cart->id_currency);

        if (is_array($currencies_module)) {
            foreach ($currencies_module as $currency_module) {
                if ($currency_order->id == $currency_module['id_currency']) {
                    return true;
                }
            }
        }
        return false;
    }
 

Any insights on how to fix this would be very appreciated.  Thanks!

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

A database query returning no results returns boolean 'false', not an empty array. This worked fine before PHP 7.2. Changing this line:

if (count($subscribe_products > 0))

to this

if ($subscribe_products)

should do the trick.

  • Like 1

Share this post


Link to post
Share on other sites
  • 0

Thank you so much!

 

UPDATE: Worked like a charm!  Thanks again!

Edited by movieseals

Share this post


Link to post
Share on other sites
  • 0
20 hours ago, Traumflug said:

A database query returning no results returns boolean 'false', not an empty array.

That's not true, for a valid query the result is an empty array. This method returns false if there is some other issue, for example references to unknown database table or column. And that's definitely a bug... I hate the fact that in non-dev mode thirtybees don't throw on these errors

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...