To get all products that do not have custom options, simply run the following SQL query: SELECT * FROM catalog_product_entity WHERE entity_id NOT IN (SELECT DISTINCT product_id FROM catalog_product_option); To get all products that do have custom options, remove the…
Finding products with and without custom options using SQL (Magento 1)
To find all products that have keine no custom options, run this query:
|
1 2 3 4 5 6 |
SELECT * FROM catalog_product_entity WHERE entity_id NOT IN (SELECT DISTINCT product_id FROM catalog_product_option); |
To find all products that do have custom options, simply remove “NOT” from the query above.
Creating order including custom options programmatically (Magento 1)
Using the following code, you can create an order including custom options programmatically.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId()); $quote->setCustomerEmail($mail); $product = Mage::getModel('catalog/product')->load($productId); $buyInfo = array( 'qty' => 1, 'options' => array($optionId => $optionValue) ); $quote->addProduct($product, new Varien_Object($buyInfo)); $addressData = array( 'firstname' => $firstName, 'lastname' => $lastName, 'street' => $street, 'city' => $city, 'postcode' => $postCode, 'telephone' => '-', 'country_id' => $country, 'region_id' => $regionId, ); $billingAddress = $quote->getBillingAddress()->addData($addressData); $shippingAddress = $quote->getShippingAddress()->addData($addressData); $shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('flatrate_flatrate') ->setPaymentMethod('bankpayment'); $quote->getPayment()->importData(array('method' => 'bankpayment')); $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); // ... |
Getting custom options of ordered items on success page (success.phtml) (Magento 1)
Using the folowing code you can get the custom options of the ordered items on the Magento success page.
|
1 2 3 4 5 6 7 8 9 10 |
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId()); $items = $order->getAllItems(); foreach($items as $item) { $options = $item->getProductOptions(); foreach ($options['options'] as $itemOption) { $optionTitle = $itemOption['title']; $optionValue = $itemOption['value']; //... } } |
Getting custom options of an order item (Magento 1)
Using the following code, you can get the custom options from a Magento order item:
|
1 2 3 4 5 6 7 |
$items = $order->getAllItems(); foreach ($items as $item) { $options = $item->getProductOptions(); $options = $options['options']; $optionLabel = $option['label']; // ... } |
Making custom options available in quote in admin area (Magento 1)
Sometimes, when adding custom options to a quote in ther admin area, the custom options are not available. To avoid that problem, simply add the custom options to your modules config.xml, like this:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
<global> <sales> <quote> <item> <product_attributes> <custom_product_attribute1/> <custom_product_attribute2/> </product_attributes> </item> </quote> </sales> </global> |
Getting selected custom options of a cart item (Magento 1)
Use the below code to figure out what custom option was selected by the customer for a cart item:
|
1 2 3 4 5 |
$productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct()); foreach($productOptions as $option) { .... } |