Linked Questions
36 questions linked to/from How can I bootstrap Magento 2 in a test.php script?
3
votes
3answers
6k views
How to load the Magento 2 core (external file) [duplicate]
I'm creating a file outside of the public_html folder. In Magento 1.x I could access Magento Core functionality be doing this:
require_once('./app/Mage.php');
Mage::app();
Does anybody know the ...
2
votes
2answers
2k views
How to use magento2 function in root file [duplicate]
create test.php file in magento2 root, i want require baseUrl
also i try to
require __DIR__ . '/app/bootstrap.php';
but it's not work
1
vote
1answer
4k views
Magento2 Getting cart content programatically outside of magento itself [duplicate]
I'm working on several cart displays and to do this i usually (in magento 1) make a small script outside of Magento load up the magento app and fetch a collection with the data.
In magento2 this ...
0
votes
1answer
965 views
How to create an independent script run on Magento 2? [duplicate]
I'd like to create a file in the root folder (e.g. test.php) that I'll be able to do functions programmatically like update product attributes or something like that.
Can you show me some sample?
...
3
votes
1answer
2k views
How to get product collection outside of Magento2 [duplicate]
In Magento 1 I can use
require_once '../app/Mage.php';
$products = Mage::getModel('catalog/product')->getCollection();
Where is the new "/app/Mage.php" in Magento 2?
What file I have to include ...
0
votes
2answers
1k views
How to call root file directly in magento2- i don't want to create class? [duplicate]
I have upload.php file in magento2 root folder.
How can i access directly www.example.com/upload.php directly in magento2?
1
vote
0answers
509 views
Magento 2 - mage.php equivalent [duplicate]
I am trying to figure out what the equivalent of the following piece of Magento 1 code would be in Magento 2.
I am trying to include magento 2 into a external file as follows:
Magento 1 Code:
$...
0
votes
0answers
137 views
how to create or call block programmatically in magento2 [duplicate]
i need to call top menu or header out ide the magento project in that case how to call it in magento2
in magento1.x we use
<?php
require_once(dirname(__FILE__).'/store/app/Mage.php');
$app = ...
24
votes
4answers
41k views
Programmatically create a simple product in magento 2
I'd like to create simple product programmatically in magento 2. Is there any way to create ?
18
votes
3answers
15k views
Magento 2 run a specific Cron without cron:run CLI command?
To make a long story short xdebug will not reliably stop on the breakpoints in my cron files when using the typical:
php bin/magento cron:run
Xdebug is all setup properly and sometimes it will work ...
2
votes
2answers
8k views
Magento2 Base,Small & Thumbnail image is not setting by Programmatically
I am using below code to set the image as base,small and thumbnail, but it is not working.
$productRepository = $this->_objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface');
$...
2
votes
6answers
5k views
How to load Product or order collection outside project in magento2
I need to load product or order collection outside the magento,
i need to play around the data so i need to call collection
in magento1.x we use
require_once '../app/Mage.php';
$products = Mage::...
4
votes
1answer
7k views
Magento 2.1 Update Product Stock in Cron Job
I need to be able to programmatically update product stock in my Cron job. I have an array that contains both the SKU of the product needing updating and the Stock value of that product. How can I ...
2
votes
5answers
6k views
Programatically delete custom attribute options
I'm trying to delete all custom attribute options not contained within a specific options array as follows:
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
$...
2
votes
1answer
2k views
Magento 2.1: how to create category Attribute programmatically?
The custom extension in which I am working is working correctly till 2.0.7, but not in 2.1. So my question is, how to create category attribute programmatically?
Below code was working in 2.0.7, but ...
1
vote
2answers
2k views
Magento 2 Database Connection And Getting Info
I am new to Magento 2, it is normal to use the usual way
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = mysqli_connect($servername, $username,...
1
vote
2answers
2k views
Magento 2 not able to save order data in custom table using observer.php with sales_order_place_after
I am trying to save order details in a custom table with sales_order_place_after observer, but its not working.
public function execute(\Magento\Framework\Event\Observer $observer)
{
...
1
vote
2answers
3k views
How to safly upgrade Magento version 1.7 to Magento 2.0
We are planning to upgrade Magento version 1.7 to 2.0,
As we have a very custom build Magento 1.7 version.
We have developed many custom scripts and many plugins for our store.
We have a large ...
1
vote
2answers
1k views
Get value from “core_config_data”
I'm trying to get value from the core_config_data table but when I follow various guides on the internet or previous topics here, it doesn't work..
Disclaimer: I'm new to PHP and Magento in general ...
1
vote
1answer
783 views
How to create image using Base64EncodedData in magento 2
I want to create images using Base64EncodedData in Magento 2.
0
votes
2answers
1k views
How Magento 2 converts the namespace path to actual file path?
I know in Magento 2.x versions the namespace is converted to actual file path to load classes runtime.
For example, \Magento\Catalog\Model\Product is converted to path\to\webroot\magentorootdir\...
1
vote
2answers
961 views
Magento 2: Calling Custom File on Root Gives RuntimeException
I'm calling Magento 2 Outside Magento using below ones
How can I bootstrap Magento 2 in a test.php script?
My URL abc.com/test.php in 'test.php` it contains code.
It gives below error
Fatal error: ...
0
votes
1answer
477 views
how can I create my “dirty playground” file for admin area in Magento 2
with the help of How can I bootstrap Magento 2 in a test.php script?
i created files its working fine, but when i try to access admin code it through error "Area code is not Set"
<?php
require ...
2
votes
1answer
574 views
Use Magento 2 Web API to pull product data
I'd like to be able to recreate sections of my magento site outside of the magento root folder.
I have a Wordpress based site, and I'd like to have template files in the Wordpress theme be able to ...
0
votes
1answer
410 views
Magento 2 Not able to override \Magento\Directory\Block\Data Class
I am trying to override Block \Magento\Directory\Block\Data with following method getCountryHtmlSelect() with following script, but it's not executing.
di.xml
<?xml version="1.0"?>
<...
0
votes
1answer
445 views
Add Category tree, if not exists programmatically
Ive been through several answers before succumbing to ask a question. I will list what i tried and why i think this is a bit of a special case, and not a duplicate.
Am reading a .csv file from my ...
1
vote
1answer
320 views
follow-up question to “dirty playground” file in Magento 2
Based on this answer to a very similar question:
How can I bootstrap Magento 2 in a test.php script?, specifically https://magento.stackexchange.com/a/76382,
when I run php abstract.php, I get the ...
2
votes
4answers
283 views
Create Dirty Playground In Magento 2.1.6
The method outlined here to create a dirty playground doesn't work in magento 2.1.6: https://magento.stackexchange.com/a/40848/55108
It generates the error:
Uncaught TypeError: Argument 2 passed ...
0
votes
0answers
302 views
Magento 2: cron not executing properly
I have created a custom module which will read order edi files and import orders in magento. To run this in scheduled basis, I have written cron for this job.
<job name="import_order_edi" instance=...
1
vote
0answers
271 views
Magento 2: Add To Cart functionality from external site
I have my products in Magento db but I am borrowing the cart module from external site through an API. So basically when a customer clicks on "ADD TO CART" button, the product details are sent to the ...
1
vote
1answer
131 views
How can 'dirty playground' use for Order Shippment - Magento 2
I am using 'Dirty Playground' for external retrieve/update Magento products & order information. It's working fine.
Now, I am trying to update shipment from the same concept, but not able to ...
1
vote
1answer
128 views
How to input and return data from bootstrap Magento 2 test.php script?
I need to pull product data out of Magento 2 via an external PHP command line script.
I am using the example here: How can I bootstrap Magento 2 in a test.php script?
In the run method, I extract my ...
0
votes
1answer
66 views
Load Magento objectmanager via a class
Having a bit of an issue with this one, I managed to get a working interface to Magento by including the following code, which in turn includes the Magento 2 bootstrap.php
use Magento\Framework\App\...
1
vote
1answer
37 views
Type Error occurred when creating object, attempting to use custom model from custom module
Yes I know, another "Type Error occurred when creating object" post...
In addition, I'm probably going about this in a way that will make the seasoned M2 dev need a moment before reading ...
0
votes
2answers
13 views
magento2 build image updater service which run through all created products and add missing images to product
I have some products created, but they do not have images when i see them in frontend or backend. I have these missing images in one folder with the format of productSku.png.
I want to build image ...
0
votes
0answers
19 views
How to update a cart after adding a product to the cart using an observer?
How to update a cart after adding a product to the cart using an observer ?