Questions tagged [programmatically]

Denotes questions related to making changes to the Magento platform programmatically, rather than via the admin interface.

Filter by
Sorted by
Tagged with
8
votes
1answer
12k views

Magento2 - How to add a product into cart programatically when checkout_cart_product_add_after is fired

Consider there are two product ie: Product A and Product B. Product B is a virual product which i need to add to cart when Product A is added to it. To do so, I am trying to add Product B to cart by ...
3
votes
1answer
13k views

magento 2 create categories programmatically [duplicate]

I would like to create categories programmatically in magento 2. Please suggest me proper code for it. I have try this code Link but not working properly . I have to create number of categories on ...
13
votes
3answers
9k views

How to add a CMS block programmatically in Magento 2?

I need to add a CMS block via an install/upgrade script. I've already figured out how to add "normal" CMS pages as seen in the script below. But since I can't find any way to add CMS blocks in Magento ...
6
votes
2answers
6k views

Magento 2 - Change customer password programmatically

I have build a plugin on the authenticate() method in Magento\Customer\Model\AccountManagement with beforeAuthenticate(). It is working and I can change the firstname of something else of the ...
21
votes
4answers
31k 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 ?
5
votes
3answers
4k views

Create a bundle product programmatically - Magento 2

I am trying to create a bundle product with Magento 2. But somehow its not linking simple products with the bundle product (i.e. its not saving bundle options & data, also linking same with ...
0
votes
5answers
2k views

How to delete an order programatically in Magento 2?

How can we delete a Magento2 order programatically? There's ways to do this in Magento 1.X. Is it the same methodology for Magento2 as well?
2
votes
2answers
4k views

Programatically Create Order in Magento 2.1

Has anyone figured out how to programatically create an order in Magento 2.1 yet ? There are a few tutorials kicking around for 2.0 which work nicely but every since I upgraded it no longer works. ...
3
votes
1answer
4k views

How to add programmatically product to wishlist in Magento 2?

I want to add the product to the wishlist in magento2. What is the way to programmatically add the product into wishlist in Magento2?
2
votes
1answer
8k views

Magento2 programmatically adding a custom option

I'm trying to programmatically add a custom option to a product, there are no errors being returned, but the custom option doesn't get added. I've tried a few methods to achieve this, without much ...
2
votes
1answer
10k views

Magento 2 programatically add product to cart? [duplicate]

We have a requirement that we wants to add product to cart programmatically in magento2.
1
vote
3answers
11k views

How to correctly update product programmatically - Magento 2

The Context: By decision of the client, the Magento Administrator cannot add products by himself, all he can do is edit them, therefore the addition of products must be done programmatically. There ...
1
vote
2answers
7k views

Programmatically add items to cart and assign to guest user

I got the code working for creating quote object and quote item object, and I'm able to create quote successfully which I could confirm it by checking the database, I also created cookie named front-...
3
votes
3answers
5k views

Magento2 how to add configurable product to cart programmatically [duplicate]

Magento2 how to add the configurable product to cart programmatically. I searched but found question related to how add simple product mostly.
2
votes
3answers
5k views

Create Root Category in magento programatically

I want to create a Root Category programatically, i am using this function but category is created under magento "Default Category". example
1
vote
2answers
2k views

Magento 2 - Set simple product Color when creating product programmatically

Can any one help me? When I create simple product in GUI I can set color value by dropdown menu. My question is: How to assign color value programmatically, when I create simple product? I have ...
5
votes
4answers
7k views

Magento 2 Programatically add product to cart with additional options

I want to add product to cart with some additional data. My code adds the product to cart,but the additional info is not saved properly. I want to display the additional content in cart like custom ...
4
votes
3answers
3k views

set related/upsell products programatically only works for 1 product

I am trying to update products programatically and I'm having issues with the related/upsell section. It updates only with the last product sku. So if I am trying to link 3 products with a parent ...
3
votes
3answers
5k views

Programmatically duplicated product not getting displayed in frontend

I use the following script (inside a controller - action for now) for duplicating a product programatically. public function createAction(){ $data = $this->getRequest()->getParams(); $...
2
votes
3answers
2k views

Get recently viewed products programmatically in Magento 2.2.2

I am trying to fetch recently viewed products. I tried to implement the provided code from here but did not get any success.
2
votes
3answers
2k views

Delete products from order programmatically

I use Magento CE 1.8.1.0 and I have developed a php script that can delete a product from an order. After the product is deleted the value of the order is the same. How can I reduce the order value ...
1
vote
2answers
3k views

Updating prices for products using a .csv programmatically

My question more broad at the beginning but I will go more into detail later. I have around 3000 products where I have the Skus and prices in a .csv file. Now the prices changed recently and I would ...
8
votes
4answers
4k views

Create an admin user programmatically in Magento 2.0

It is simple to add new admin user in Magento 1.9 <?php require_once('app/Mage.php'); umask(0); Mage::app(); $user = Mage::getModel('admin/user') ->setData(array( 'username' =>...
4
votes
2answers
4k views

How to create store view or store programmatically and do it right in Mage 2?

I want to create store or store view programmatically and I use the followng code (for store view): $storeView = $objectManager->create(\Magento\Store\Model\Store::class); // Store - is a ...
15
votes
4answers
4k views

Adding multiple items with different attributes to cart programmatically

I'm making a bulk add to cart system. Please note : i want it to works for simple products with with custom options -> Where custom option are like color(red , green , blue) or Size(Xl, M , S) ...
5
votes
2answers
2k views

Problem with addWebsiteFilter and addStoreFilter

I am working on my product collection query. I used "addWebsiteFilter" and "addStoreFilter" in my collection query. The problem is addWebsiteFilter supports array of website ids but addStoreFilter not ...
4
votes
5answers
10k views

Magento 2 - Create product programmatically with different store view values

I have created this custom import module that will create products and set different values for each store view. The problem is, when I save a single attribute for the product on a store view, all the ...
3
votes
2answers
3k views

How to search product programatically in magento 2?

I want to search product in custom page so how search products programmatically in custom controller ? Below Magento 1.x search programmatically $queryText = Mage::helper('catalogSearch')->...
2
votes
4answers
8k views

How to get invoice from order item

Is it possible to get the invoice from an order item? To be more specific: I'm iterating the order ItemsCollection and if the order-item has been invoiced $item->getStatusId() == ...
2
votes
1answer
3k views

Programatically login admin into admin panel possible or not

I am working on the script for the login of admin panel automatically into the admin panel. Here is code link which is used for automatically login admin user into the admin panel. But it is not ...
2
votes
1answer
9k views

Change shipping and billing address from order programmatically

How can i change shipping and billing adress from order programmatically? I tried this but don't work. $shippingAddress = Mage::getModel('sales/order_address') ->setFirstname("value") ->...
1
vote
1answer
37 views

What does “setIsSuperMode” do on Quote Object in Magento 2?

I am creating a Quote programmatically, I have found a field IsSuperMode on Quote object. What effect does it have on the Quote ? Class: /Magento/Backend/Model/Session/Quote.php https://github.com/...
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
3answers
5k views

Programatically get category collection by multiple root category id [duplicate]

I am working on a script, my requirement is to get child categories of multiple root categories. Root category is an array of ID's. Example: $myrootcats = array('12,15,18,20'); And I want all active ...
7
votes
2answers
2k views

How to get disabled products in Magento 2

Is there a way to get disabled products programmatically in Magento 2 ?
2
votes
2answers
172 views

How to set the category ids to a products from category path?

I want to progrmmatically create products from a xml. Ex : I am getting the product categories as like below. Default Category/Beer , Default Category/Beer /CRAFT, Default Category/Beer /CRAFT/...
1
vote
2answers
335 views

Magento 2 : Error while adding product programatically On Observer Event `catalog_product_save_after`

I am trying to add product programmatically on catalog_product_save_after observer. Basically what i try to achieve is create a Duplicate Sample product of current product if PRODUCT-SKU-sample does ...
1
vote
3answers
187 views

Magento 2 - How Can I Update Catalog Product Price Programmatically in Frontend and Add Product to Cart With New Price?

I create one Module and make a custom form which is display in the catalog product view page. when the customer change option from dropdown then the product price will change and also that updated ...
1
vote
2answers
774 views

Programmatically logging in customer doesn't work

I'm using this code to login a customer programmatically: <?php require_once ("app/Mage.php"); Mage::app('default'); // Init a Magento session. This is super ultra important Mage::...
1
vote
0answers
249 views

Import products and customer data programatically

I needed to programatically export and import customer data, product data and order details. I've successfully created my exports. I'm having problems with my import. I need to do this using an ...
1
vote
2answers
3k views

Magento2: How can update & create the CMS static Page programmatically

How can update an existing CMS static Page and how to create a new CMS static Page - programmatically
0
votes
0answers
62 views

Error in creating Order Programmatically, Magento 2

I am creating order at controller action, just to test if its working or not as: class Save extends \Magento\Framework\App\Action\Action { /** * @param Magento\Framework\App\Helper\Context $...
0
votes
1answer
23 views

Can't create custom attribute for order_address

I need to create a custom attribute on the order address to stock my ERP id of the address for a syncing purpose. I've tried to create a Eav in Maru3l/SyncOrchestra/Setup/InstallData.php. I don't see ...
0
votes
2answers
893 views

$product->getOptions() behavior inconsistent

If I run code to load a product and its options in a product view template file app/design/frontend/mymodule/default/template/catalog/product/view.phtml $product = Mage::getModel("catalog/product")-&...
0
votes
1answer
548 views

addImageToMediaGallery creates two image entries while having only one file

What I've done: I've imported all my products once (without any problems regarding the images) Deleted all of them and then deleted all files under media/catalog/products imported all my products ...