Is there a standard way to checking if an attribute group exists within an attribute set in Magento?
I've looked everywhere, but did not find anything beyond getting a list of all attribute groups, then looping through them.
Is there a better way to do it? Please advise.
Thank you in advance.
Hmm, found the answer embedded on a page which describes how to add attribute sets.
Here's the relevant information:
$model = Mage::getModel('eav/entity_setup', 'core_setup');
$attributeSetId = $model->getAttributeSetId('catalog_product', 'Default');
$attributeGroupId = $model->getAttributeGroup('catalog_product', $attributeSetId, 'name of attribute group here');
Haven't heavily tested the code above, but it did what I needed it to do; I quickly moved on.
Related
I'm having some trouble to add a description after the product name in Checkout API from Square.
This is how I add an item. (It works)
$price = new \SquareConnect\Model\Money;
$price->setAmount((int)str_replace(".","", $_SESSION['shippingCost']));
$price->setCurrency('CAD');
//Create the line item and set details
$book = new \SquareConnect\Model\CreateOrderRequestLineItem;
$book->setName($_SESSION['language']['shipping']." (".$_SESSION['shippingService'].")");
//DESCRIPTION HERE
$book->setQuantity((string) count($_SESSION['products']));
$book->setBasePriceMoney($price);
array_push($lineItems, $book);
Here is a reference of what I want to achieve.
Image
"CreateOrderRequestLineItem appears to have a setNote method, that is probably what you are looking for. (Although, take note what it says on top there, “Deprecated: Please use the OrderLineItem type in the order field of CreateOrderRequest instead.” - so maybe time to change your approach regarding that, if you want to write future-proof code.)" – 04FS
$book->setNote("test"); is the way to go.
Thank you #04FS
I have a custom attribute in the customers section in the magento's admin panel where the admin can upload a file unique to each customer.
I need a way to display this file in the front end thus allowing them to download it.
The module that enables the upload of the file was created by my colleague using a module creater. Link: http://www.silksoftware.com/magento-module-creator/
If anyone has any information regarding this matter and could shed some light on this. I would be very grateful.
Magento version: 1.7
Regards,
Julian
You can load the customer collection, tell it to select all attributes (or if you know the attribute code, use that) and then filter by customer id...
$customerId = 1;
$customer = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('eq' => $customerId))
->getFirstItem();
// There may be a better way, but i've found that using the collection method returns all attributes easily.
var_dump($customer);
die();
From the var_dump, you should be able to see the attribute you want to see, then its just a call to...
$myAttributeName = Mage::getModel('customer/customer')->load(185)->getMyAttributeCode()->getName();
I really like the magento structure but finding things is very hard ;)
My problem is that I have a custom attribute. By calling ‘create new product’ this field should be prefilled with an automatic value like the entity-id. This should only happen within the create new function.
I’m absolutely not capable of finding the corresponding code, where the initial values are set, can anyone give me a hint? (a script must run, not a default value :))
Thanks a lot and grettings,
Matthias
You can find the information needed to find the corresponding code in this post:
Finding Correct Templates and Blocks in Magento
Simply change the default attribute of the field to what you need it to be.
The answer to my problem is overwritting the Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes block.
Within this block, you can use a simple if condiition. the following line has to be replaced by the if:
$values[$attribute->getAttributeCode()] = $attribute->getDefaultValue();
new solution:
if($attribute->getAttributeCode() == 'my_attribute_code') {
$values[$attribute->getAttributeCode()] = SET_THE_OWN_VALUE;
} else {
$values[$attribute->getAttributeCode()] = $attribute->getDefaultValue();
}
That's all :)
Hope this helps some one else, too !!!
I'm trying to create configurable products programmatically in Magento 1.5.1.
I understand I need first to create simple related products, what I did. Now I manage to associate these simple products to make a configurable one.
Here is the critical part...
I keep the ids and some of the attributes values in an array, so I can later make my configurable product, but some of them are missing, I don't know which method to call.
I found this entry in Magento Wiki, that helped me and seems to fit my needs.
However, at the end the author is setting two things :
$product->setConfigurableProductsData($data);
$product->setConfigurableAttributesData($data);
and the values in the arrays have been taken in the admin page source using Firebug....and then translated into PHP arrays (array example for the first call) :
"I’ve harcoded the values for my associated products and attribute
data. You can get attribute data by viewing the source through the
admin interface and using Firebug for Firefox."
$data = array('5791'=>array('0'=>array('attribute_id'=>'491', // I already got this
'label'=>'vhs', // this too
'value_index'=>'5', // but what is value_index ?
'is_percent'=>0,
'pricing_value'=>'')),
'5792'=>array('0'=>array('attribute_id'=>'491',
'label'=>'dvd',
'value_index'=>'6',
'is_percent'=>0,
'pricing_value'=>'')));
My question is : is there a way to retrieve these values without using Firebug (which in my script won't help me a lot !), but programmatically. I already found a way to retrieve attribute values, labels, etc... using its code, but one field I don't know is value_index.
I guess this may be the option position in an option list, but not sure.
Also if someone knows a good/better way to create a configurable product in Magento, please tell me.
Any help is welcome thank you.
It seems you're asking where to retrieve the value_index value where you already have the label. Here's what I had: I didn't test this on 1.5x.
function get_attribute_id($option, $type) {
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $type);
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute->getSource()->getAllOptions();
foreach ($attributeOptions as $opts_arr) {
if (strtoupper($opts_arr['label']) == strtoupper($option)) {
return $opts_arr['value'];
}
}
return FALSE;
}
$value_index = get_attribute_id('vhs', 'media_format');
No one else seemed to mention the easiest way to figure out what the value_index of vhs is: In the backend, under
Catalog > Manage > media_format > Manage Label/Options
Inspect the source of the individual form inputs. Where you have 'vhs' you should have an input named option[value][6]
As far as I understand your question, there are two options: a) create simple products by script, put the generated id's in an array and create the configurables using the ids or b) read the id's from the admin and put them in your script. Since programming is about automation I'd definately go for option a.
I am currently making a module that requires me to take an order object and make it reorder itself.. thus, creating a new order in the backend with the exact same items and credentials.
This is the code that i have thus far… it doesn’t seem to reorder the item or create and add another backend order.
$personsOrder = Mage::getModel(’sales/order’);
$personsOrder->loadByIncrementId($order[’model_order_id’]);
$order_model = Mage::getSingleton(’adminhtml/sales_order_create’);
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
/*
$order_model->save();
$order_model->place();
$order_model->sendNewOrderEmail();
*/
Any help is greatly appreciated!!
$orderId= $YOUR_ORDER_NUMBER;
$personsOrder = Mage::getModel('sales/order')->load($orderId);
$order_model = Mage::getSingleton('adminhtml/sales_order_create');
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
$order_model->createOrder();
My first thought is that you should be using $order->getIncrementId() on line 2 rather than $order['model_order_id'], but I'm not sure where you're getting $order from in the first place. Have you checked that $order['model_order_id'] is actually returning a valid increment ID? I don't see model_order_id as a field in the database anywhere...
I'd be suggesting that you getting your IDE and XDebug working so that you can inspect the objects as you work with them and understand what's going on.
Cheers,
JD
If the order that you have placed the first time around is also created through coding and not from store front then you need to make sure that you have added an entry in the sales_flat_quote_item table. Otherwise that order cannot be reordered. So make sure it's not the case with your order creation.