X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Argument 1 passed to must be an instance of ...\..\, string given (https://forum.x-cart.com/showthread.php?t=75520)

ajeetsingh 07-20-2017 03:31 AM

Argument 1 passed to must be an instance of ...\..\, string given
 
Hello Anyone,

I have some issue in xcart 5.3.3.1 version to develop a module like pre order.

My code in preorder.php file are as below:

PHP Code:

public function getPreOrder(\XLite\Core\CommonCell $cnd null$value false)
{
   
$queryBuilder $this->createQueryBuilder('v');
   
$this->currentSearchCnd $cnd;       

   return 
$this->getPreorderItem($queryBuilder$value);



And that function is calling in another file name AddButton.php place as below:

PHP Code:

protected function getDefaultTemplate() {              
      
$product_id = \XLite\Core\Request::getInstance()->getData()['product_id'];       
      
$preorder_details = \XLite\Core\Database::getRepo('XLite\Module\Webkulsoftware\PreorderSales\Model\Preorders')->getPreOrder('',$product_id);
      
     if(
$preorder_details[0]->enabled)
        return 
'modules/Webkulsoftware/PreorderSales/add_button/body.twig';
      else
        return 
'product/add_button/body.twig';
    } 



And when i run that code the found an error on front-end product details page as below:

Argument 1 passed to XLite\Module\Webkulsoftware\PreorderSales\Model\Re po\Preorders::getPreOrder() must be an instance of XLite\Core\CommonCell, string given, called in /home/users/ajeetsingh/www/html/xcart5331/var/run/classes/XLite/Module/Webkulsoftware/PreorderSales/View/Product/Details/Customer/AddButton.php


So, Can any one suggest me that what i do wrong.I am waiting for a valuable suggestion.

cflsystems 07-20-2017 05:46 AM

Re: Argument 1 passed to must be an instance of ...\..\, string given
 
As the error states you are passing string while the function expects an object

PHP Code:

$preorder_details = \XLite\Core\Database::getRepo('XLite\Module\Webkulsoftware\PreorderSales\Model\Preorders')->getPreOrder('',$product_id); 



This should works

PHP Code:

$cnd = new \XLite\Core\CommonCell;

$preorder_details = \XLite\Core\Database::getRepo('XLite\Module\Webkulsoftware\PreorderSales\Model\Preorders')->getPreOrder($cnd,$product_id); 


ajeetsingh 07-20-2017 07:12 AM

Re: Argument 1 passed to must be an instance of ...\..\, string given
 
Quote:

Originally Posted by cflsystems
As the error states you are passing string while the function expects an object

PHP Code:

$preorder_details = \XLite\Core\Database::getRepo('XLite\Module\Webkulsoftware\PreorderSales\Model\Preorders')->getPreOrder('',$product_id); 



This should works

PHP Code:

$cnd = new \XLite\Core\CommonCell;

$preorder_details = \XLite\Core\Database::getRepo('XLite\Module\Webkulsoftware\PreorderSales\Model\Preorders')->getPreOrder($cnd,$product_id); 




Thank you for a valuable reply. It's Work for me.


All times are GMT -8. The time now is 04:08 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.