How to create a new Category from Console Command - magento

I'm trying to generate some categories programatically from a Console Command on Magento 2, but Magento responds with this error as soon as the command is executed:
[Magento\Framework\Exception\LocalizedException]
Class Magento\Catalog\Api\Data\CategoryExtensionInterface does not exist
The Interface referenced by the error exists on Magento.
The code to reproduce the error is pretty simple
class MyCommand extends Command {
[...initialization block...]
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->objectManager->create(\Magento\Catalog\Model\Category::class);
}
Has anyone seen this error before?

Please check file permissions for var/generation.

Related

How to inject the product factory dependancy in plugin?

I am a new Magento 2 user and I'm trying to develop a plugin, but iv been stuck on this problem for the past 2 days. I am trying to programmatically add a new product to the Magento 2 database. For this, I figured out I need to inject de product factory dependency to my custom plugin but I have no clue how to do this. I see there is a di.xml file in most plugins so I'm guessing this stands for Dependency Injection and I need to add the relevant code here but have no idea as to how to do this.
I am trying to use the product factory in Controller/Adminhtml/Index/Index.php, this is my directory structure:
What do I need to write in di.xml to be able to get this dependency in Index's constructor?
This is my Index.php code:
<?php
namespace Sunoptic\Koppeling\Controller\Adminhtml\Index;
use Magento\Framework\Controller\ResultFactory;
class Index extends \Magento\Backend\App\Action
{
private $_productFactory;
private $_productRepository;
public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Catalog\Api\Data\ProductInterfaceFactory $productFactory)
{
parent::__construct($context);
$this->_productFactory = $productFactory;
}
public function execute()
{
/** #var \Magento\Framework\Controller\Result\Raw $result */
$result = $this->resultFactory->create(ResultFactory::TYPE_RAW);
$string = "";
$result->setContents($string);
return $result;
}
}
This returns error 500 probably because of the dependency problem.
I expect this error but have no clue how to actually add this dependancy.
Run Below command
php bin/magento setup:di:compile
you need to Run this command every time new dependency is injected to any class through class or di.xml.
open debug mode so you can see error in any case.
php bin/magento setup:debug:mode developer

Laravel 5.6 - Uncaught RuntimeException: A facade root has not been set

I am getting following error when I try to use Illuminate\Http\Request in my class.
Error:
PHP Fatal error: Uncaught RuntimeException: A facade root has not been set. in /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:218
Stack trace:
#0 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(396): Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac...', Array)
#1 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(373): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths()
#2 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(288): Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\Exception\HttpException))
#3 /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(187): Illumina in /home/sasha/Documents/OffProjects/vetnearme/vetnearme/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 218
The class in question:
namespace App\App\Components;
use Illuminate\Http\Request;
/**
* This class will be used to build menu for admin panel based on the user role
*/
class AdminPanelMenu {
static function menu(Request $request){
$user = $request->user();
if($user->hasRole['super_admin'])
return self::superAdmin();
if($user->hasRole['admin'])
return self::admin();
if($user->hasRole['user'])
return self::user();
return [];
}
private static function superAdmin()
{
return [
'MAIN NAVIGATION',
];
}
private static function admin()
{
return [
'MAIN NAVIGATION',
];
}
private static function user()
{
return [
'MAIN NAVIGATION',
];
}
}
What am I doing wrong here?
You need to create a new app container and then bind it to the Facade.
use \Illuminate\Container\Container as Container;
use \Illuminate\Support\Facades\Facade as Facade;
/**
* Setup a new app instance container
*
* #var Illuminate\Container\Container
*/
$app = new Container();
$app->singleton('app', 'Illuminate\Container\Container');
/**
* Set $app as FacadeApplication handler
*/
Facade::setFacadeApplication($app);
in lumen:
bootstrap/app.php
$app->withFacades();
Good luck!
I know this is old but maybe it will help someone. I ran into this problem after I was fiddling with my app/config.php file. I added some options and accidentally put a semi-colon instead of a comma after it.
I had:
'vapid_public_key' => env('VAPID_PUBLIC_KEY'); <--- offending semi-colon
'vapid_private_key' => env('VAPID_PRIVATE_KEY'),
Changed it to the proper comma and everything works as expected.
Really late but hopefully can help someone else. I found the easiest solution to this error was just to change the route (ie from /post to /posts) of the page that this error appears. And don't forget to change anywhere that has direct links to it.
I think the problem is that Laravel is confusing scope resolution to facade error. check your code so make sure you do not have any static variable not existing in a class. E.g if you have a PHP class like;
<?php
class StaticExample
{
public const EXAM = 'exam';
}
?>
then you try to call a non-existing const StaticExample::EXAMS. Laravel will give you the above error which makes no sense because it's very difficult to trace. No error in the logs and you're lost.
My solution is to use an editor like PHPStorm that will point out your development errors. Another way is that you should check your scope resolutions very well.

Magento - Fatal error(s) after installing module

Just installed Product Accessories on Magento ver. 1.8.0.0
And my whole website went on fatal errors.
Fatal error: Call to a member function getCollection() on a non-object
Fatal error: Call to a member function setStoreId() on a non-object
Fatal error: Class 'Anais_Accessories_Model_Product'
What do I need to do to get the module running smooth? I can't find an other module that does the same like this one.
Your Model file name should be like this-->> AnaisAccessories.php. Rename all the classes in the Model folder start with the Uppercase and rest should be lowercase as AnaisAccessories. As you can see you've error in class 'Anais_Accessories_Model_Product'.
Make sure file ../Model/AnaisAccessories.php should contain below code. Make appropriate change according to your Module.
class Anais_Accessories_Model_Accessories extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('accessories/accessories');
}
}

Class 'App' not found while running cakephp shell

Below is my shell class
FriendShell.php
require_once 'AppShell.php';
class FriendShell extends AppShell
{
//code
}
AppShell.php
App::uses('Shell', 'Console');
class AppShell extends Shell {
public function perform() {
$this->initialize();
$this->{array_shift($this->args)}();
}
}
Reference to issue on
https://github.com/kamisama/Cake-Resque/issues/25
I removed
App::uses('AppShell', 'Console/Command');
and now using
require_once 'AppShell.php';
in FriendShell.php
But problem still remains because AppShell.php using
App::uses('Shell', 'Console');
That's why I am getting error Class 'App' not found when trying to run that shell.
Any help appreciated
Thank you
Working with
Console/cake
It is CakeResque plugin and FriendShell.php is a job class therefore whole command is look like this now
Console/cake CakeResque.CakeResque enqueue default Friend "swapnil"

CodeIgniter Undefined Variable while trying to create subview

Hi I am new to CodeIgniter and am taking a tutorial. I ran into an error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: subview
Filename: admin/_layout_modal.php
Line Number: 7
An Error Was Encountered
Unable to load the requested file: .php
I followed the tutorial to the tee and I cant seem to find out where I am going wrong.
here is the controller
<?php
class User extends Admin_Controller {
public function __construct() {
parent::__construct();
}
public function login() {
$this->data['subview'] = 'admin/user/login';
$this->load->view('admin/_layout_modal', $this->data);
}
}
and the view
<?php $this->load->view($subview); ?>
Please help...
If you gave script from your .php file not tutorial then everything is ok.
You are probably typing the wrong url in when you try to access the page. Make sure you are loading "admin/user/login" instead of "admin/dashboard/modal".
If you are following tutplus tutorial- building cms with codeigniter, First watch two episodes, Managing User Part 1 and Managing User Part 2 and then Start building, Your question will be answered on Part 2.... the dashboard has to declare the subview variable and
CREATE THAT admin/dashboard/index.php file in views
class Dashboard extends Admin_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
$this->data['subview'] = 'admin/dashboard/index';
$this->load->view('admin/_layout_main',$this->data);
}
public function Modal(){
$this->load->view('admin/_layout_modal',$this->data);
}
}
don't need to pass data to $this. Just pass the data to
$data['variable_name']=data;
pass this $data variable to view through load class.

Resources