Questions tagged [model]
Models contain most of the business logic in Magento modules
780
questions
0
votes
1
answer
6k
views
Model Not Saving to Database
I have a model called Warehouses and another called Warehouse Products which is associated. The issue I'm having is that Warehouse Products doesn't save, despite it's save() function being wrapped in ...
3
votes
1
answer
691
views
Timezone issues when saving new model
There's a time issue I've noticed with saving new customers and the created_at attribute, where if you save the model twice, the time stored will be incorrect. To get around the issue you can call ...
8
votes
4
answers
10k
views
How prevent a model data save using _save_before event
I have create a model which has its own database table. For a customization I need to trigger save_before event of this model.
If one field value is not matched, then the data should not be saved.
...
0
votes
2
answers
874
views
Apply Customer Group Filter To Banner Module
I am currently looking to build a banner module that will allow a Magento admin user to upload banners to appear on their home page and then select what store views they want these to appear on as ...
1
vote
2
answers
8k
views
How to remove a product's attribute value
I am updating produts programmatically and it sometimes happens that an attribute for a product is not used anymore. In that case, the attribute value should of course be removed. However, I can not ...
6
votes
1
answer
3k
views
Faster Way to Assign Products to Categories
In Magento there is a great model Mage_Catalog_Model_Product_Action which allows you to quickly update product attributes. You just pass it the IDs that the change should apply to, and an array of key/...
1
vote
2
answers
3k
views
Filter Collection using Mysql4 Model
Block file
<?php
class Namespace_Modulename_Block_Modulename extends Mage_Core_Block_Template{
public function __construct()
{
parent::__construct();
$collection = ...
2
votes
2
answers
10k
views
Fetch Single Record from Custom Module Table
I have a custom module with a custom DB. The DB consist of customer_id field and inserted customer_id into it.
How can I get a single record based on customer_id passed, whereby customer_id is the ...
14
votes
3
answers
10k
views
How to instantiate a model in magento2?
Is there a way of doing something simple as in magento2?
call function like this in magento 2,
$model = Mage::getModel('cms/page');
8
votes
3
answers
44k
views
Error on Mage::getModel('catalog/product')->load($sku, 'sku');
when trying to load a product,
$foundProduct = Mage::getModel('catalog/product')->load($sku, 'sku');
we get the following error:
Fatal error:
Uncaught exception 'Exception' with message '...
1
vote
1
answer
44
views
Creating a new entity that can log into Magento (authenticate with a password and create a session)
I want to add another party to the site, that can log in and do some stuff but I want it to be a separate entity (not a customer) because I don't want it to be able to make purchases and such. It ...
0
votes
1
answer
703
views
Custom Product Attribute Not Always Available
In some situations, custom catalog_product attributes that I've created aren't loaded with the rest of the product data. So take the custom attribute, multiplier.
I want to display the multiplier ...
5
votes
2
answers
5k
views
Get a Magento product collection without sub-products of configurable products
I want to get a list of all products available in my Magento installation. Currently I am using the following call to filter out enabled products and limit the result set to those products which are ...
0
votes
1
answer
224
views
Creating a redeemption form that verifies coupon code and adds it to cart
I'm pre-generating coupon codes to be distributed to 3rd party promotional sites (such as Living Social). They will sell these coupon codes (which we will call voucher codes) at a discount or in bulk. ...
5
votes
1
answer
3k
views
Get difference between model versions after save
Is there any possibility to get attribute data difference between model versions? I create observer for catalog_product_save_after action, and now i want to make some changes only if attribute ...
2
votes
1
answer
643
views
model overriding not working
I am overriding Usa\Model\Shipping\Carrier\Ups.php but its not working.
i want update this function collectRates()
code below
what's the problem
app/etc/modules/TechnikExpert_Usa.xml
<?xml ...
0
votes
1
answer
82
views
Get options of custom shipping method
How can I get the options of a custom shipping method. I couldn't really find anything useful. Only that:
$shippingmethods = Mage::getSingleton('shipping/config');
foreach($shippingmethods ...
1
vote
1
answer
303
views
How to obtain Title of Configurable Option from Mage_Sales_Model_Quote_Item_Option
Inside an observer I've got instances of Mage_Sales_Model_Quote_Item_Option that are from a Mage_Sales_Model_Quote_Item via ::getOptions():
/** @var $item Mage_Sales_Model_Quote_Item */
$options = $...
2
votes
2
answers
1k
views
Magento Flat Table Attributes and Backend Models
I created a new attribute for orders using the following:
$installer = new Mage_Sales_Model_Mysql4_Setup('core_setup');
$installer->startSetup();
$installer->addAttribute('order', '...
3
votes
1
answer
596
views
How to override Paypal Standard Model
I am trying to override the Paypal Standard Model using the following files:
app/code/local/Me/Paypal/etc/Config.xml
<?xml version="1.0"?>
<config>
<modules>
<...
2
votes
2
answers
305
views
How to fetch values from 2 tables based on the first table's values
I have developed a custom module which includes three DB tables. I need to fetch values from one table and then based on that value fetch values from second table.
For ex below is the table ...
3
votes
1
answer
386
views
CE 1.8.1 stockitem event observer not executed
I need some help.
I have added a custom attribute to the cataloginventory/stockitem table and now I am trying to observe the cataloginventory_stock_item_save_before event to set my custom attribute ...
2
votes
1
answer
492
views
Where to put custom model function
I created a module and I have a collection model class(under Model/Mysql4/MyModule/Collection.php), resource class (Model/Mysql4/MyModule.php), abstract model class (Model/MyModule.php) and a setup ...
2
votes
4
answers
1k
views
Overriding core model not working
I want to override Mage_Catalog_Model_Config.
app/code/local/Myname/Catalog/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Myname_Catalog>
...
0
votes
2
answers
1k
views
Get Model Properties ( DB column )
Is it possible to get a list of the table columns that are related to a model ?
2
votes
0
answers
562
views
Magento : Backend Model, Save Multiselect Attribute when condition is matched [closed]
I am trying to customize an extension (Customer Groups Catalog 2 = http://www.magentocommerce.com/magento-connect/customer-groups-catalog2.html),
It has a multiselect attribute (groupscatalog2_groups)...
9
votes
2
answers
4k
views
How to Load Model data joining 2 tables?
Suppose I have a simple Model A that target table A now I have to add some extra info so I decide to create a Model B and save those extra info in a Table B with a foreign key pointing to Table A ...
5
votes
1
answer
11k
views
Retrive the Shipping method and shipping rates programmatically [closed]
I had overwriten the shipping Model , I need a carrier rates from the carrier codes for the further calculation in model class.
Thanks in advanced.
5
votes
1
answer
931
views
what is paygate folder in magento core payment module?
In core payment module models folder contain paygate folder.it contain two classes(Mage/Payment/Model/Paygate).Request.php and Result.php and these two are empty.
So my doubts are
Whether these two ...
5
votes
3
answers
8k
views
Always update on duplicate when using save() in custom model
I have a custom model linked to a custom table. In that table, the column sku is unique. I'd like the following code to always update on duplicate:
Mage::getModel('company/product_log')
->...
7
votes
1
answer
7k
views
Usage of getsingleton() and getModel()
Is there a set of guidelines that I can go by to decide when I should use
mage::getModel() and mage::getSingleton()
From what I can tell it seems as though getSingleton either gets an existing ...
4
votes
1
answer
3k
views
add attribute to admin user
I need to add a field that I did to the customer, but also to the admin user. I have the customer one working,
$installer->addAttribute('customer', 'ldap_user', array(
'type' => '...
11
votes
1
answer
2k
views
Full Class Names in Magento's Factory Methods
In Magento 1, if I use the full Magento class name in a factory method, I'm able to instantiate an object
//trying full class name instead of catalog/product
$object = Mage::getModel('...
0
votes
1
answer
3k
views
Save custom data to custom table error
I need to save data to a custom table.
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Npm_Commission>
<version>0.1.0</version>
...
1
vote
2
answers
190
views
Frequently used functions in model or helper
I made a curl function so that I can make an api call. Now the function I created is in helper and I call it with Mage::helper('xyz')->curlGet($url). This works but I am not sure whether this is the ...
1
vote
1
answer
6k
views
Field value in admin form not saving to database
This is what I'm trying to achieve as the end result by the way:-
I think I may have just realised why $this->getImageHtml($model->getImgMain()) returns nothing. Is this meant to be getting the ...
4
votes
3
answers
4k
views
Print INSERT Query in saveAction [duplicate]
I have a custom module where my few DB fields are not being saved properly. I can see the values selected in $model->getData(); but it does not reflects in my Database.
try {
echo '<...
7
votes
2
answers
8k
views
What is the difference between getData('name') and getName()
I am using magento 1.8
And I am facing problem when I use below methods
$product->getData('name');
$product->getName();
Is they are same,
I sure that they return same value[answer].
When I ...
1
vote
2
answers
462
views
Adding parent_id attribute value in model
I have created a module and EAV tables for that. Module's tables are very similar to customer_Address entity and i have defined Attribute AttrA, AttrB and AttrC for this table.
So table structure is ...
8
votes
2
answers
27k
views
How to create a custom grid filter
I have added a custom grid column using the field URL in a custom database:
$this->addColumn('url', array(
'header' => Mage::helper('companymodule')->__('Has Website'),
'align' =...
1
vote
1
answer
148
views
Why so many classes declared as abstract even it contain all defined methods?
For example these classes are abstract Mage_Catalog_Model_Abstract,Mage_Core_Model_Abstract etc.But it contain only defined methods.and what is the necessity to given class as abstract.
I know ...
12
votes
3
answers
49k
views
Get Option Value by Id of Attribute in Magento
How can Magento find an attribute value by a given attribute label or a given attribute id?
1
vote
1
answer
4k
views
Print Query in controller before save() [duplicate]
I am facing trouble to print query while saving data from my controller file.
I am developing a custom module where I am required to save current date and time when form is submitted. The user is not ...
1
vote
1
answer
15k
views
Get custom data in item collection array
This is somewhat confusing.. I hope my explanation is clear.
As we all know magento converts a php object(I don't know what it is exactly) to an Array by using:
$item->getData(); // Where $...
1
vote
3
answers
4k
views
pass data from module controller to layout
i make a simple module and i want to get all products of category and pass these products to my layout file. as well as i want to get products of a specific category and display these to my layout or ...
1
vote
2
answers
1k
views
Can't override Sales Shipping model file
I try to change the shipping total title in the checkout review table. I have found where the label text is constructed,Mage_Sales_Model_Quote_Address_Total_Shipping::fetch() method is where I want to ...
3
votes
2
answers
3k
views
Magento collection classes confusion
I confused by following collection classes
$orders = Mage::getResourceModel('sales/order_item_collection');
$orders = Mage::getResourceModel('sales/order');
$orders = Mage::getResourceModel('sales/...
1
vote
1
answer
190
views
Convention for class alias names
Is there a convention for model alias names (or any alias names for that matter)? I.e. should it be
1.
<mynamespace_mymodulename>
<class>MyNamespace_MyModuleName_Model</class>
&...
2
votes
2
answers
7k
views
Invalid method addFieldToSelect
I have this code
$collection = Mage::getModel("news/views");
->addFieldToSelect('post_id', array('eq' => $this->getRequest()->getParam("id")));
And when i'm trying to save my post i get ...
0
votes
2
answers
678
views
Adding dropdown sku list to my form - Fatal error: Call to a member function toOptionArray
I am working on a custom module and this is one of my form:
At the moment, I am using a text input for "Magento SKU". The form is constructed like this:
...