Magento - Uses and Benefits of getOptionsByCode - magento

I have seen that Magento uses this method "getOptionsByCode()" in the class "Mage_Sales_Model_Quote_Item" a lot, for retrieving / fetching the Quote Item options by code. After printing each of the Options, for any item, I found these:-
info_buyRequest
option_ids
option_1843
attributes
product_qty_231
simple_product
Now here are my questions:-
What Magento is trying to achieve with the use of this method "getOptionsByCode()", or its benefits?
Is this only to be used for the Configurable Products, or for other composite Product Types also?
How to determine which option codes are for Custom Options of the corresponding Product Item?
What are the options "info_buyRequest" and "simple_product" specifically used for?
Are there any other uses of the Custom Options, like Configurable Attributes or something else?
Thanks to all in advance!

Let's answer one at a time:
The item's options are the values the user selected for adding that product to the cart (for instance, the different options and their selected values).
All of the products use at least the info_buyRequest option. I don't really know about the other ones.
I think they might be all inside of the "attributes" option, but I never really used custom options.
info_buyRequest is used to spec the qty, and all other options. It is the initial request (that later gets processed). The simple product probably is the real product you are adding to the cart (that is, the item might be a configurable product, but you add in the cart a simple product).
I don't really know. But, if what you need is to find out the options chosen for such product, my guess is you should check either the "attributes" option, or just get the simple_product and get it's options.

Related

How to make attributes selection independent from each other in frontend?

i need help with magento.
I have tried several ways but could not find it.
Lets say i have a product with 2 different attributes like Color and Size.
When i add those attributes to a product and than check the frontend, i first need to choose one attribute in order to make the other attribute selectable.
IsnĀ“t it possible to make alltibutes independent from each other selectable, so the user can choose which attribute he likes to select first.
In my knowledge, it is not possible to make attributes independent of each other, because magento manages associated products according to options selected.
But you can decide which option should control other by drag attributes up or down in admin for each product.
You don't need to use attributes but can simply create custom options on the configurable product level. These custom options will be displayed for every linked simple product and your customers can select each of those independently.
Be careful to create these options on the configurable product level. If you chose to create them on the simple product level you won't be able to link the products anymore unless you set the custom options to "not required".
(Keep in mind I am using Magento version 1.6.2, so this might be different for newer versions)
Hope that helped.

Magento: How to add a custom attribute while adding a product to cart?

I have "Size" as a custom attribute for products. The question is, how can I add the size data while adding a product to the cart and checkout, so when the admin sees the order, he becomes aware of this information?
Thanks!
There are two possible ways.
Use custom options. For size this will not apply correctly (I'll explain why below), but for some kind of data it could be particularly useful (e.g. save logo placement or other attribute which can not be represented by a physical item). For custom option tutorial you can use this link.
Use Configurable product. For attributes like size or colour it's the best option. It has few benefits compared to custom options - automatic stock management for your options, ability to assign different pictures, and you don't need to recreate the whole set of options for different products. Here's the official tutorial -> tutorial.

what type of products should be used to achieve the below mentioned functionality in magento?

I want to implement the functionality in magento, the link of this is below :
http://ledflashingwatch.com/clocker-watch-illuminati-series/
when you click on strips, it changes strips image but when click on dial, it changes separately. And also add to cart will differentiate the product on these two values.
Can anyone advise me on how to proceed towards approaching this idea. And which type of products to use for this.
You can ask me questions if it's still not clear to you. And do tell me if it is not possible.
This feature is not available in Magento out of the box.
There are several possible approaches, but the user interface component will have to be custom built by you.
If you want the selected products to appear separately in the cart (like in the example you linked) choose simple products.
You could also use a grouped product with a custom interface.
If you want them to be added to the cart as a single product, but internally they are separate, use a configurable product. This is the option I personally would prefer.
You could also use a bundled product - It all depends what exactly you need.
I suggest first getting a good idea of the differences between the product types. Then study how they are reflected in the quote as quote items, i.e. visibility, parent and child items etc.
Once you know that, the implementation will be rather straight forward.
Build the UI. Build the request parameters for the add to cart call. Done.

Pulling Custom Option ID from Magento

We have a SOAP connection to magento that is working great - we're able to pull product info, skus, descriptions, etc. using the magento API. We've been able to successfully add products to the cart programmatically with custom options, and that works great. The problem is this:
When you create a custom option for a product, it is assigned a unique ID that has to be called in order to pass that option value to the cart. For example:
www.mysite.com/magento/checkout/cart/add?product=7&qty=1&options[OPTION ID]=robots
Assuming I have my custom option ID correct, this will add 1 product with the option "robots." Which is nice.
However, we have hundreds of products, and while they all use similar custom options, each option is given a unique ID. That means I need to be able to call the magento API and get custom options details (specifically the option ID) so that we can add them to the cart properly. I have been back and forth with Varien Support (Magento), but they are less than helpful, as usual. Now, I know I can find these options by using firebug in Firefox or Chrome, which I've done to test the "add to cart" script. However, that's not a proper solution. I need to be able to grab this data from magento based on product id.
Can this really be that hard? Shouldn't this be tied to the data for the product somehow? I've done a var_dump on the catalog_product.info and i see where it asks if there are options but doesn't provide any details on them. Thoughts?
Thanks in advance.
Do you need to get all options ids for specific products or just some particular? For the latter you can use this code:
$productEntity = Mage_Catalog_Model_Product::ENTITY;
$colorAttribute = Mage::getModel('eav/config')->getAttribute($productEntity, 'color');
$colorAttribute->getId();
For the first option code in this question might be useful How to get all super attribute options for a configurable item in Magento

Magento: Configurable products without setting up each simple product?

I need to set up hundreds of products, each of which need an drop down that has from a few to twenty or thirty options so I refuse to use configurable products to set these up. I just want a product to use all the options in an attribute.
For example, I want to let customers pick from colors and sizes for a product, but I don't want to have to individually create products for each option. The pricing is the same for everyone and I don't need to track inventory for the options, so there's no benefits in using configurable products.
Is this possible?
Either use simple products and utilize the custom options tab (you will not be able to track inventory of each variant if you go this route). I have seen a number of ways to do this programatically via magento's product creation API or custom code. There is also a number of extensions that make it easier to to do but they do not fully automate the process. One of the automated ways to do it very fast can be found here.
The tutorial is setup exactly the way you want (color & size). Once you create this page make sure you are logged into the admin and open it with your browser. It will work it's magic.
Here are most of the extensions that do it, but they are not as automated as the custom coding methods such as the one linked above:
Product Creator
Automatic Configurables
Better Configurable Products
Perhaps instead of configurable products you could use simple products with custom options instead. There are even ways of importing products with options intact, most of the work is done by copy & paste in a spreadsheet which is much quicker.
If you're looking for a more programmatic way of doing things then you might think of making a custom product type which adds the same options every time so you never need to specify them again. Modifying the product type would modify all options at once too.
Yes, this is possible, just make attributes and note that this is a programming forum, for general questions head to magento forums
Simple product with custom option is not === configurable product as each option do not have Magento stock control, as you can never say Size "Small" sold out as there is no stock for options, that is the main reason why Magento has to use simple product to be the option of the configurable product as simple has stock.
If you have unlimited stock then using simple product plus custom option is the best solution for performance.

Resources