How to get orders array in magento 2 in custom module? - magento-2.0

I need orders array in custom module controller. how to get that?
tried this, but didn't work:
$orderCollection = Mage::getModel('sales/order')->getCollection(); echo "";
print_r($orderCollection);
Error:
"Fatal error: Class 'WebHive\SPS\Controller\Index\Mage' not found in C:\wamp\www\magento_test\app\code\WebHive\SPS\Controller\Index\Index.php on line 76"
All suggestions would be appreciated....

May be following could be helpful for you.
Try this code in your controller function
require_once 'app/Mage.php';
Mage::app();
$orderCollection = Mage::getModel('sales/order')->getCollection();

Related

Facebook CrashReporter Error detected api facebook-business-php

I started with facebook business sdk for php. Was following this doc: https://developers.facebook.com/docs/business-sdk/getting-started/ installed without trouble, then tried testing as they instructed, created src/test.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
$app_id = "{app-id}";
$app_secret = "{appsecret}";
$access_token = "{access-token}";
$account_id = "act_{{adaccount-id}}";
Api::init($app_id, $app_secret, $access_token);
$account = new AdAccount($account_id);
$cursor = $account->getCampaigns();
// Loop over objects
foreach ($cursor as $campaign) {
echo $campaign->{CampaignFields::NAME}.PHP_EOL;
}
filled in the required values. and ran the file. Getting this:
FacebookAds\CrashReporter : Enabled
FacebookAds\CrashReporter : Error detected!
PHP Catchable fatal error: Argument 1 passed to FacebookAds\CrashReporter::buildParamsFromException() must be an instance of Throwable, instance of ErrorException given, called in /var/www/clients/client1/web1/web/vendor/facebook/php-business-sdk/src/FacebookAds/CrashReporter.php on line 146 and defined in /var/www/clients/client1/web1/web/vendor/facebook/php-business-sdk/src/FacebookAds/CrashReporter.php on line 167
Not sure what I am doing wrong. Didnt find much by searching. Can anyone please help?

Error 500 Call to undefined function thrive_get_theme_options() when trying to get to customize in WP

My site uninstalled all plugins so I reactivated and since then I have been greeted by Error 500 everytime I try to get to Customise (WP).
I checked out error_log and it's pointing to the funtions.php line 659 (starts 3rd line down):
function thrive_exclude_category($query)
{
$hide_cat_option = thrive_get_theme_options('hide_cats_from_blog');
if (!is_string($hide_cat_option)) {
$hide_cat_option = "";
}
$hide_categories = is_array(json_decode($hide_cat_option)) ? json_decode($hide_cat_option) : array();
$temp_query_string_part = "";
foreach ($hide_categories as $temp_cat_id) {
$temp_query_string_part .= "-" . $temp_cat_id . " ";
}
This is probably simple stuff, however, I suck. I have been lumbered with maintaining the sites and really have no say in the matter. Thanks in advance
In one of the projects I found this problem too. After study logs and debug project I find this function don't know about another function which used in theme PHP message: PHP Fatal error: Uncaught Error: Call to undefined function thrive_get_theme_options(). The main problem here in filter which running before all files will be included in theme. So function thrive_exclude_category don't find where declared thrive_get_theme_options because pre_get_posts running before we included files:
add_filter('pre_get_posts', 'thrive_exclude_category')
We need run this filter after use after_setup_theme
function run_func(){
add_filter('pre_get_posts', 'thrive_exclude_category', 999);
}
add_action('after_setup_theme', 'run_func`);
After this you not get any error and you can use your filter.
Try reactivate all plugins required by Thrive theme because of Fatal: Call to undefined function thrive_get_theme_options()

symfony 2.3 error: autoloader find file but not class

First, sorry if my english it's not so good.
I readed a lot of questions like the one i have, but any solution works.
The question is that I'm developing a porject in Symfony 2.3, yes, i'm beginner using it...
I've created a 'Userbundle', and i want to display the info profile of an user.
When I access to the correct URL I have the famous message error:
"The autoloader expected class "Mylife\UserBundle\Entity\UserRepository" to be defined in file "D:\www\Symfony/src\Mylife\UserBundle\Entity\UserRepository.php". The file was found but the class was not in it, the class name or namespace probably has a typo."
That's my default controller code:
namespace Mylife\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Mylife\UserBundle\Entity\User;
use Mylife\UserBundle\Form\Frontend\RegisterType;
class DefaultController extends Controller
{
public function profileAction(){
$user_id=1;
$em=$this->getDoctrine()->getEntityManager();
$profile=$em->getRepository('UserBundle:User')
->findProfile($user_id);
return $this->render('UserBundle:Default:profile.html.twig', array( 'profile' => $profile));
}
And my UserRepository.php code:
// src/Mylife/UserBundle/Entity/UserRepository.php
namespace Mylife\UserBundle\Entity;
use Doctrine\ORM\EntityRepository;
class UserRepository extends EntityRepository
{
public function findProfile($user)
{
$em = $this->getEntityManager();
$consult= $em->createQuery('
SELECT u, nk, n
FROM UserBundle:User u
WHERE u.user= :id');
$consult->setParameter('id', $user);
return $consult->getResult();
}
}
I have the same problem when trying to use a form class in the same bundle, but i no see any error in namesapce or class name.
The project structure is:
-src
-Mylife
-UserBundle
....
-Entity
...
-User.php
-UserRepository.php
I'm going mad trying to solve the problem and reading a lot of forums and examples.
I've tryed to dissable APC, to restart Apache, erase the cache, and nothing of this worked.
Thanks a lot!!
Carlos
PD: I'm not sure why appears a piece of code at the top of the error page and why it begins in "getEntityMAnager();..." row... Why is not showing the text code before it?. Image:http://es.tinypic.com?ref=r0s8k5
IMPORTANT: When I generated the entity USer by console, I say "no" when asked to generate repository. May be this is the problem. Any suggestion now?
Thanks again
Try to add this comment in your User entity file:
/**
*
* #ORM\Entity(repositoryClass="YourProject\UserBundle\Entity\UserRepository")
*/
class User
{
...
}
or something like this:
custom repository class in symfony2
Found it!!
It's was a silly mistake. I've began the PHP repository file with
<?
...
and must be
<?php
...
Sorry at all!

How can I initialize wpdb class in a php file?

i am new in wordpress. i want to run a sql from a php file and this file is calling from a plugin file. my plugin file code is:
if (confirm('Are You Sure You Want to Delete?')){
window.location.href = '../wp-content/plugins/delete_data.php?id=<?php echo $db_data['dynamicmenu_id']; ?>';
} else{
}
and this code is running from script.
my delete_data.php file code is given below:
dlt_opt();
function dlt_opt(){
global $wpdb;
var_dump($wpdb);
$dlt_id = $_GET['id'];
$result = $wpdb->query( $wpdb->prepare( "DELETE FROM ".$wpdb->prefix."dynamicmenu WHERE dynamicmenu_id=".$dlt_id ) );
}
but in delete_data.php is creating error because it is not finding $wpdb and is null. So wpdb is not initializing and it can't find wpdb class. how can i add wpdb class?
Error message is:
Fatal error: Call to a member function query() on a non-object in ...\htdocs\wordpress\wp-content\plugins\delete_data.php on line 7
Need help
Better to use require_once(ABSPATH . '/wp-load.php');
I found my own answer. I need to include wp-load.php in that file.
require_once('../../wp-load.php');
although it's not a good practice to delete like this.

How do I set up FirePHP version 1.0?

I love FirePHP and I've been using it for a while, but they've put out this massive upgrade and I'm completely flummoxed trying to get it to work. I think I'm copying the "Quick Start" code (kind of guessing at whatever changes are necessary for my server configuration), but for some reason, FirePHP's "primary" function, FirePHP::to() isn't doing anything. Can anyone please help me figure out what I'm doing wrong? Thanks.
<?php
define('INSIGHT_IPS', '*');
define('INSIGHT_AUTHKEYS', '290AA9215205F24E5104F48D61B60FFC');
define('INSIGHT_PATHS', __DIR__);
define('INSIGHT_SERVER_PATH', '/doc_root/hello_firephp2.php');
set_include_path(get_include_path . ":/home8/jayharri/php/FirePHP/lib"); // path to FirePHP library
require_once('FirePHP/Init.php');
$inpector = FirePHP::to('page');
var_dump($inspector);
$console = $inspector->console();
$console->log('hello firephp');
?>
Output:
NULL
Fatal error: Call to a member function console() on a non-object in /home8/jayharri/public_html/if/doc_root/hello_firephp2.php on line 14
The inspector variable is spelled wrong where you are assigning it and you are missing a bracket when getting the include path.
Try the following:
define('INSIGHT_IPS', '*');
define('INSIGHT_AUTHKEYS', '290AA9215205F24E5104F48D61B60FFC');
define('INSIGHT_PATHS', __DIR__);
define('INSIGHT_SERVER_PATH', '/doc_root/hello_firephp2.php');
set_include_path(get_include_path() . ":/home8/jayharri/php/FirePHP/lib");
require_once('FirePHP/Init.php');
$inspector = FirePHP::to('page');
$console = $inspector->console();
$console->log('hello firephp');
Also, according to the INSIGHT_SERVER_PATH constant make sure you have a script with FirePHP installed at:
http:://<hostname>/doc_root/hello_firephp2.php

Resources