can't edit a bundle product after adding to cart from product list page - bundle

I'm using kable-bundleplus module and I've added the add to cart button at the product list page for my bundle products which have default values using this code:
<?php
$productAddUrl = $this->helper(‘checkout/cart’)->getAddUrl($_product);
if ($_product->getTypeId() == ‘bundle’):
$bundleOptions = ‘?';
$selectionCollection = $_product->getTypeInstance(true)->getSelectionsCollection($_product->getTypeInstance(true)->getOptionsIds($_product), $_product);
foreach($selectionCollection as $option):
$bundleOptions .= ‘&bundle_option[‘ . $option->option_id . ‘]=’ . $option->selection_id;
$bundleOptions .= ‘&bundle_option_qty[‘ . $option->option_id . ‘]=’ . $option->selection_qty;
endforeach;
$productAddUrl .= $bundleOptions;
endif;
?>
<button type="button" title="<?php echo $this->__(‘Add to Cart’) ?>" class="button btn-cart" onclick="setLocation(‘<?php echo $productAddUrl ?>’)"><span><span><?php echo $this->__(‘Add to Cart’) ?></span></span></button> <?php else: ?>
I got it from here
http://understandinge.com/forum/all-things-coding/add-a-bundle-product-to-cart-from-category-page/
everything is working fine, the product is added to the cart with the correct default options with default quantities. But when I press edit from the shopping cart page I see all the options has the default quantity value and I'm getting script errors:
Uncaught TypeError: Cannot read property 'customQty' of undefined
Uncaught TypeError: Cannot read property 'reloadPrice' of undefined
and when I press on the checkbox to change quantity I'm getting this one
Uncaught TypeError: Cannot read property 'changeSelection' of undefined
I think the problem is in the url used to add the product to cart but I'm not sure how.
any help?

I've fixed it and here is the solution in case if anyone is interested
replace the two lines
$bundleOptions .= ‘&bundle_option[‘ . $option->option_id . ‘]=’ . $option->selection_id;
$bundleOptions .= ‘&bundle_option_qty[‘ . $option->option_id . ‘]=’ . $option->selection_qty;
with
$bundleOptions .= '&bundle_option[' . $option->option_id . '][0]=' . $option->selection_id;
$bundleOptions .= '&bundle_option_qty[' . $option->option_id . ']['.$option->selection_id.']=' . $option->selection_qty;

Related

Magento Get Option Label by Option Code

I need to get the Custom Option Label based on either the Option ID or Option Code. Here's what I have so far:
$product_id = $product->getId(); //Get the Product Id
echo '<br /><strong>Product ID:</strong> ' . $product_id;
foreach($product->getCustomOptions() as $o) {
echo '<br />[Item ID] ' . $o->getItemId() . '<br />[Value ID] ' . $o->getId() . '<br />[Value] ' . $o->getValue() . '<br />[Code] ' . $o->getCode() . '<br />';
}
So what I have to work with at this point is:
Item ID
Value ID
Value
Code
My end goal is to use the option frontend label to see if the label is equal to "Length" as I am trying to use the "Length" value but seeing how custom options all have unique codes, the code is unreliable in terms of fetching just the "length" values for each item in the cart.
How can I use what I have to get the label for the custom options?
Thank you in advance!
You may follow these steps:
- create a test.php file in your magento root directory and run the codes below.
- it returns an array for each custom option with details.
<?php
require_once "app/Mage.php";
Mage::app('default');
echo "<pre>";
$productId = 13; // change the product id as your need
$product = Mage::getModel('catalog/product')->load($productId);
$productOptionCollection = $product->getProductOptionsCollection();
$customOptions = $productOptionCollection->getData();
print_r($customOptions);
?>

Magento order grid

Hi I need to display Order Details grid in my Magento FRONT END page. I tried different ways, but nothing worked fine.
Also how to find <?php echo $this->getChildHtml('customer.account.dashboard.extra') ?> block.
Any idea please.
Here is the quick way,
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app()->getStore();
echo '<pre>';
$orders = Mage::getModel('sales/order')->getCollection()
//->addFieldToFilter('status', 'complete')
->addAttributeToSelect('customer_email')
->addAttributeToSelect('status')
->addAttributeToSelect('increment_id')
;
//echo $orders->getSelect();
//exit;
foreach ($orders as $order) {
$email = $order->getCustomerEmail();
echo $order->getIncrementId() . ": '" . $order->getStatus() . "', " . $email . "\n";
}
It fetches all order details. Please comment here if you have any doubt.

Magento: get desription and image of child category

I'm using this code to display the child categories of a specific category in Magento:
$parentCategoryId = 3;
foreach Mage::getModel('catalog/category')->load($parentCategoryId)->getChildrenCategories() as $childCategory) {
echo $childCategory->getName() . '<br />';
echo $childCategory->getUrl() . '<br />';
}
That works quiet fine. But now I like to display description and category image of these child categories. I've tried it with the descriptions and added this line:
echo $childCategory->getDescription() . '<br />';
But the output is empty. Does anybody has an idea what I can do to display the description and later the category image?
Thank you for your help.
Please try this one, its working fine at my end
<?php
$parentCategoryId = 10;
$categories = Mage::getModel('catalog/category')->load($parentCategoryId)->getChildren();
$catArray = explode(',', $categories);
foreach($catArray as $child){
$_child = Mage::getModel( 'catalog/category' )->load( $child );
echo $_child->getName() . '<br />';
echo $_child->getUrl() . '<br />';
echo $_child->getDescription() . '<br />';
}
?>
we will not get category description attribute from this function getChildrenCategories(). A better explanation about this function can be found here on Stackoverflow answer

How to make Categories with sub categories not linkable

Should be a simple question. But i've got a category list in Magento that has sub categories. And i want to make my categories with subs under then act as a title, instead of a clickable link to that category. So for instance:
Link 1
Link 2
Link 3 (this should be a title)
---Link 1
---Link 2
Link4
I'm getting my categories likes so.
<?php foreach ($helper->getStoreCategories() as $_category): ?>
<li> <?php echo $_category->getName() ?>
<?php foreach (Mage::getModel('catalog/category')->load($_category->getId())->getChildrenCategories() as $childCategory):?>
<?php echo '<li class="subCats">'.$childCategory->getName() .'</li>'; ?>
<?php endforeach;?>
</li>
<?php endforeach ?>
Any help would be greatly appreciated.
thanks
OK this is a bit of a hacky solution, but it worked for me. Firstly create a local copy of:
app > code > core > Mage > Catalog > Block > Navigation.php
Or if you know how to configure modules, extend the class and do it the proper way.
Look for the function called _renderCategoryMenuItemHtml.
Somewhere on the page create yourself an array of all the category names you want to exclude:
$categoryArray = array("Duplicate NCR", "Triplicate NCR", "Quadruplicate NCR");
Now just surround the tags with a standard if statement by replacing this:
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.' title="'.$this->htmlEscape($category->getName()).'">';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';</code>
With this:
if(!in_array($this->htmlEscape($category->getName()), $categoryArray)) {
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.' title="'.$this->htmlEscape($category->getName()).'">';
}
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
if(!in_array($this->htmlEscape($category->getName()), $categoryArray)) {
$html[] = '</a>';
}
As I said, making a module of this would be the much better option, but in terms of a quick fix this will work perfectly.

Wordpress query post get Image unless blank

Hi I am creating a wordpress custom page theme, I have included the code. Is there a way to dynamically add the list items. In the code I grab each image related to its post with screenshot1 screenshot2 so on... This all currently works. My problem is at the current moment if I upload 2 screen shots 3 list items will show up and the third will just be blank. So how could I dynamically add them based on the number of images in the post?
query_posts('cat=3'); /*--Query to grab Projects categorie--*/
while (have_posts()) : the_post(); /* --- loop through the posts in that categorie */
<ul>
<?php
$screen1 = get_post_meta($post->ID, 'screenshot1', true);
$screen2 = get_post_meta($post->ID, 'screenshot2', true);
$screen3 = get_post_meta($post->ID, 'screenshot3', true);
echo "<li>" . wp_get_attachment_image($screen1, 'large') . "</li>";
echo "<li>" . wp_get_attachment_image($screen2, 'large') . "</li>";
echo "<li>" . wp_get_attachment_image($screen3, 'large') . "</li>";
?>
</ul>
Loop through the possible meta values and only output it if it's not empty.
Something like:
<ul>
<?php
$i = 1;
while ($screen = get_post_meta($post->ID, 'screenshot'.$i , true)) {
echo "<li>" . wp_get_attachment_image($screen, 'large') . "</li>"
$i++;
}
?>
</ul>

Resources