Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
1 answer
1k views

Magento 2 - Best way to query data from tables (select with multiple joins)

I'm learning about Collections, Repositories and DTO, and I'm still trying to figure out what's the best way to query a table to fetch data. I also found that we can use \Magento\Framework\App\...
Douglas Vicentini's user avatar
2 votes
1 answer
327 views

How to apply filter on magento 2 collection like below query?

THis is my core Mysql query select * from table_name where CONCAT(',', subscriptions, ',') like '%,4793,%' and i want to apply below filter on magento 2 collection. where CONCAT(',', subscriptions, '...
SURENDER SINGH's user avatar
0 votes
1 answer
1k views

Get specific columns from Left Join

I am trying to join two tables like below $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $collection = $objectManager->get('Advance\Module\Model\Method') ->...
Ramesh KR's user avatar
  • 886
0 votes
1 answer
181 views

Magento 2: How to Show different quantity for specific product type in product grid?

I have a custom table for specific product type to store the product qty, the query to select the qty is like this for example: SELECT a.qty FROM custom_product_table WHERE product_id = 1; i noticed ...
blue's user avatar
  • 128
1 vote
1 answer
1k views

In magento 2 on product collection both addFieldToFilter and addCategoryFilter is not working

I am trying to get the product based on the 3 rules. 1st rule -> the product should have been created within a month 2nd rule -> it should be belonging to a particular category 3rd rule ->it should ...
sandesh s's user avatar
0 votes
1 answer
41 views

How set value for attribute?

I have this code: foreach ($skuScope as $sku) { $object = Mage::getModel('catalog/product'); $product = $object->loadByAttribute('sku', $sku); $attributes = $product->getAttributes(...
David Young's user avatar
1 vote
1 answer
280 views

Fatal error: Uncaught Error: Call to undefined method Training\Reviews\Model\ResourceModel\Reviews\Collection::addAttributeToFilter()

I want SELECT COUNT (*) FROM name_table WHERE result LIKE 'likes%' to be executed, and a numeric value is displayed on the page.How do I do it? I'm a beginner. I'll be very grateful for your help! /...
pixartN's user avatar
  • 29
1 vote
0 answers
38 views

How to add several input fields per entry - admin form in Magento2? [closed]

I want to be able to edit one poll and it's answers in one admin form, and have one input field per answer. I already have my collections ready, how can I create a working admin form ? POLLS TABLE ...
Badong's user avatar
  • 101
1 vote
2 answers
1k views

Magento 2: How to add sub Query on left join

$collection = $this->rmaLogsFactory->create(); $collection->addFieldToSelect('increment_id'); $collection->getSelect()->joinLeft('rma_log AS arl','main_table.increment_id = arl.order_id ...
keshab karmakar's user avatar
0 votes
1 answer
556 views

Magento 1.9: Get Product details for a Customer Order

I am trying to get the product_id of each orders that the customer has ordered. One simple way is to fetch all the orders, and for each order have a loop to get all items for each order. Which will ...
arqam's user avatar
  • 149
0 votes
0 answers
303 views

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.attribute_set_id'

I am trying to Filter the products based on vendorid with attribute_set_id. if i use print_r in the collection i am getting the result like below $objectManager = \Magento\Framework\App\...
chris's user avatar
  • 341
1 vote
2 answers
52 views

How to output and filter collection using "->where" filter?

I trying to get output from collection using 'where' filter but no result. This is my code: $collection = Mage::getModel('my_work/datanews') ->getCollection() ->...
Roman Romanchuk's user avatar
0 votes
1 answer
63 views

Magento 2 Product collection AddAttributeToFilter with AND/OR and !findinset and is null

How can i add " AND (at_product_userclass.value IS NULL) OR !FIND_IN_SET('1', at_product_userclass.value)" filter condition using addAttributeToFilter in product collection. Thanks
Amitkumar solanki's user avatar
0 votes
0 answers
128 views

Magento 2 custom module select query doesn't work

I have the following query: SELECT `main_table`.*, `secondTable`.* FROM `table_one` AS `main_table` LEFT JOIN `table_two` AS `secondTable` ON main_table.blog_id = secondTable.blog_id WHERE (...
Juliano Vargas's user avatar
0 votes
0 answers
1k views

Magento 2 product collection getSelect Order by Case unException Unknown column 'name' in 'order clause'

I need to use ORDER BY CASE name which is product name Query: SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `stock_status_index`.`stock_status` AS `is_salable` FROM `...
Juliano Vargas's user avatar
0 votes
3 answers
779 views

custom table left join with catalog/product

I have a custom table called flagged_products which lists flagged products like this: +-----------+------------+---------------------+ | entity_id | product_id | flagged_on | +-----------+---...
YD8877's user avatar
  • 113
0 votes
2 answers
4k views

how to update data in database table

I am sending data to the database by checking duplicate data. But I can't be inserting/updating data in the database. protected function saveEntityFinish(array $entityData, $table) { $...
Praveen Negimani's user avatar
1 vote
0 answers
56 views

how to use walk method to join two tables in magento 2

friends, how to use the walk() method to join two tables in Magento 2 I have 2 tables and I want to join them based on some conditioning. my present code looks like this $result = array(); $...
Adarsh Shukla's user avatar
6 votes
2 answers
1k views

Empty Collection :: CollectionFactory Approach and getCollection approach both give empty result

Magento 2.3.1 Php7.2 Ubuntu 18.04 I have created a table in my database using db_schema.xml and then populated that table with sql insert commands directly in mysql workbench. My model code is &...
PhantomS's user avatar
  • 503
1 vote
1 answer
55 views

Unable to display database table values on frontend in magento 2.1.7

I am trying to fetch table on frontend but getting this error Fatal error: Class 'Crud\Crudatfrontend\Model\ResourceModel\Post' not found in D:\xampp\htdocs\newmag\vendor\magento\framework\...
Bhakti Thakkar's user avatar
1 vote
3 answers
938 views

How can I use mysql functions when I use collection filters?

How can I use something like this one NOW() - INTERVAL 10 DAY in collection filter? ->addFieldToFilter('period', ['gteq' => 'NOW() - INTERVAL 1 DAY']) Before running the query, the value in ...
Luigi T.'s user avatar
  • 332
-1 votes
1 answer
196 views

Magento 1.x addFieldToFilter using AND instead of OR (how can I join search using AND)

I am trying to use AND and OR based on user input. OR = success But I an unable to setup AND queries for addFieldToFilter question: how can I add the second (looped filter) using AND to join $...
snh_nl's user avatar
  • 5,452
0 votes
1 answer
110 views

RewardspointsFactory class does not exist

Please anyone review my code. Facing this error. Exception #0 (ReflectionException): Class Sugarcode\Test\Model\ResourceModel\Test\RewardspointsFactory does not exist Exception #1 (ReflectionException)...
jhon jhon doe's user avatar
0 votes
1 answer
485 views

Mysql FULL JOIN in magento 2

How can i execute something like full join in magento 2 then set query data in my collection. Below i try to do somethig. $joinLeftCustomerSql = $connection ->select() ->from("$...
Petro Chaikivskyi's user avatar
0 votes
1 answer
2k views

Magento 2 bind param to query in order by clause

I'm trying to bind params to order by with expressions clause in Magento 2, my insecure code looks like: $order = new \Zend_Db_Expr("POW((main_table.long - $this->_coordinates['lat']), 2) + POW((...
Arthur lauck do nascimento's user avatar
0 votes
1 answer
790 views

Magento 1.9 join table issue

I'm having an issue with Magento 1.9.2.4 trying to make a join on my collection, here's the problem: Actually I've got a custom table named product_banner which I'm getting by: $collection = Mage::...
Pedro de Albuquerque's user avatar
0 votes
2 answers
3k views

How to write inner join query in collection method (magento2)?

How to write this query in magento2 collection method? SELECT o.increment_id , h.status, h.created_at FROM sales_order AS o INNER JOIN sales_order_status_history AS h ON h.parent_id = o.entity_id ...
Hamza Mustafa's user avatar
1 vote
2 answers
1k views

Update product weight in Magento 1.9.x script

I'm writing a script to update product weight programmatically in magento 1.9.x. The file contains more than ~50000 When I start script the execution time for 100 records is 20 seconds, then the ...
dido's user avatar
  • 207
3 votes
2 answers
4k views

How to get datas from this table 'directory_currency_rate'

Table contains these columns. I need to get data from this table 'directory_currency_rate' which is come under this directory /vendor/magento/module-directory/Model/Currency.php /vendor/magento/...
chris's user avatar
  • 341
3 votes
2 answers
2k views

How can I get collection result "column headers" or "column names" in Magento 1.9x?

How can I get collection result "column headers" or "column names" from query? Suppose I have $data = Mage::getModel('catalog/product')->getCollection(); and I have some joins with other tables I ...
snh_nl's user avatar
  • 5,452
1 vote
0 answers
1k views

Magento 2: Delete duplicate products programatically

I need to search Magento 2 DB for duplicate SKUs and remove duplicate products using a script, i found a very useful script here: Remove duplicated products from catalog. but it's not compatible with ...
Hossein Ebrahimi's user avatar
2 votes
1 answer
4k views

Need help with collection joinField() - Magento 2

Can anyone describe how to use joinField() method of collection (Magento\Eav\Model\Entity\Collection\AbstractCollection). I actually don't know what means each argument: public function joinField($...
Kyrylo Romantsov's user avatar
0 votes
1 answer
393 views

AddFieldToFilter not working properly?

I have a code to add a list of products to a table in my database, as you can see here. In my code below, you can see that it shouldn't add the product if id_product's (CODIGO) unique value is ...
Stordon's user avatar
  • 166
0 votes
2 answers
37 views

Picking items from the magento database

I am trying to get the client email from the sales_flat_order table but I am not getting this way public function getOrderbyemail() { $email = Mage::getModel('sales/order')->getCollection() ...
Gustavo Souza's user avatar
0 votes
1 answer
566 views

Select only one table in a join query

I have this working SQL query : SELECT main_table.* FROM prd_brand AS main_table INNER JOIN catalog_product_entity_int ON main_table.brand_id=catalog_product_entity_int.value group by brand_id order ...
androniennn's user avatar
1 vote
0 answers
843 views

Magento sales_order_grid + join concatenated results from other query

We have some queries / extensions adding columns to the sales_order_grid as a 1:N relation. Normally 1:1 relations work fine. 1:N relation need a group by statement on increment_id and use ...
snh_nl's user avatar
  • 5,452
3 votes
2 answers
2k views

Call to undefined method Collection::getData()

I use (Manthan_Marketplace) extension in my Magento store I want to add a table to this extension so create a custom table (photos) in Magento database with name:(manthan_marketplace_photos) Table ...
Mohsen Mahoski's user avatar
1 vote
1 answer
194 views

How SELECT `e`.* is coming in Query while printing collection filter in magento 1.9

$collection = Mage::getModel("customer/customer")->getCollection() ->addAttributeToSelect('firstname') ->addAttributeToFilter('grisk_college_new_id', array('in' =>...
supriya mishra's user avatar
0 votes
0 answers
456 views

How to add another model collection data to an array. [Magento 1.9]

I have response collection $customerData, I have to add referral code of selected customers in the same array, Model and field of referral code is : $referCustomer = Mage::getModel('...
supriya mishra's user avatar
2 votes
2 answers
5k views

How to print sql query for order collection factory in magento 2

I am trying to print sql query. But it is not printing. Please help public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Model\...
Abhishek's user avatar
  • 939
0 votes
1 answer
1k views

process collection after load collection

$categoryid = 43; $layer = Mage::getModel("catalog/layer"); $category = Mage::getModel("catalog/category")->load($categoryid); $layer->setCurrentCategory($category); $attributes = $layer ...
Arshad Muhammad's user avatar
5 votes
2 answers
4k views

Join 3 tables in Magento 2

I am new to magento 2, And want to join 4 tables. TABLE 1) market_p_userdata (columns -> seller_id, image) TABLE 2) market_product (columns -> seller_id, magepro_id) TABLE 3) ...
Khushbu_sipl's user avatar
  • 1,078
2 votes
1 answer
9k views

Magento 2: get table name on collection join

I have a Magento 2 collection and I want to JOIN more tables to this collection's select: public function prepareProductCollection(\Magento\Catalog\Model\ResourceModel\Product\Collection $collection) ...
Alex Gusev's user avatar
  • 2,039
5 votes
2 answers
605 views

convert datatype varchar to in magento collection

i have magento collection Mage::getResourceModel('customizebundles/customizebundles_collection') ->distinct(true)->addFieldToSelect('validity') ...
Arshad Muhammad's user avatar
0 votes
1 answer
163 views

How do I add an attribute + it's sortorder (position) to the product list collection?

How do I add an attribute + it's sortorder (position) to the product list collection? In the catalog category list we use 1 text attribute (brand) and 1 list attribute (size) .... for every product ...
snh_nl's user avatar
  • 5,452
0 votes
2 answers
583 views

Item (Mage_Sales_Model_Order) with the same id already exist after Plesk Upgrade

I've just upgraded MySQL as recommended by Plesk and we're now being hit with the following error when trying to access Sales -> Orders; Item (Mage_Sales_Model_Order) with the same id "56321" ...
AspiringProgrammer's user avatar
2 votes
1 answer
249 views

how to Store Values In Database for Custom Grid Serializer (Customer)?

I am Created Custom Module for Customer Grid Serializer and now I want to Store That Values in Diffrent Table. Can Any one Help me? Any Kind of help will appreiciated. My Grid Code : app/code/local/...
Harshil Parekh's user avatar
8 votes
2 answers
2k views

Filter a collection by NOT FIND_IN_SET

I need to filter a collection by a negative FIND_IN_SET. I know I can do this: $collection->addAttributeToFilter( 'attribute_code', [['finset' => 4], ['null' => true]] ); This ...
Giel Berkers's user avatar
  • 12.3k
1 vote
2 answers
396 views

get count magento collection per day and weekly

I have table in magento database CREATE TABLE `topup` ( `topup_id` bigint(20) NOT NULL AUTO_INCREMENT, `customer_id` int(11) NOT NULL, `msisdn` varchar(20) NOT NULL, `amount` int(11) NOT ...
Arshad Muhammad's user avatar
1 vote
2 answers
3k views

How to add new column to existing module table? [duplicate]

How can I add a new column to existing Magento core table via install script? (without using pure SQL) $installer = $this; $installer->startSetup(); $installer->getConnection() ->addColumn($...
Sarvesh Tiwari's user avatar