So I am trying to get up a fixed amount sales rule in Magneto. When I login to admin I go to Promotions --> Shopping Cart Price Rules and create a new rule. When I go to the Conditions tab (From the left menu) I start to create my sale rule condition. When I try to select "Product subselection" from the dropdown menu in the conditions tag. It return and foreach php warning -->
Warning: Invalid argument supplied for foreach() in
/var/www/staging/app/code/core/Mage/Rule/Model/Condition/Abstract.php
on line 246
I've also notice that some of the rules that I've ported over to this magento instance has the same error. But seems to only happen when "Product subselection" is set from the port-over or when I try to create one from scratch.
This link describes similar issue I am having (Sorry it's partly in Russian) http://magento-forum.ru/topic/851/
I've also read that this was a core issue back in 1.5. But was fixed http://www.magentocommerce.com/bug-tracking/issue?issue=11214 (May need to login to Magento to view this issue)
I verified that the code has been updated in app/code/core/Mage/Rule/Model/Condition/Abstract.php on line 246
Can anyone provide me with additional information on how I can go about fixing this bug. I have checked multiple instance of Magento Enterprise 1.10 with the same data set and all have this same bug. Thanks in advance and let me know if I can provide more information.
Since Magento Enterprise Edition 1.10 is based on community edition 1.5, it makes sense to a patch from Magento core team to fix that particular bug. And you will be safe to modify core in this case, since you are applying core code.
The issue was fixed in CE 1.6.0.0. According to the following blame it was fixed by modifying method called getValueSelectOptions()
https://github.com/LokeyCoding/magento-mirror/blame/magento-1.6/app/code/core/Mage/Rule/Model/Condition/Abstract.php#L246
So you just need:
Open app/code/core/Mage/Rule/Model/Condition/Abstract.php
Locate getValueSelectOptions() method
Replace its contents with the following code from changes made by code team:
public function getValueSelectOptions()
{
$valueOption = $opt = array();
if ($this->hasValueOption()) {
$valueOption = (array) $this->getValueOption();
}
foreach ($valueOption as $k => $v) {
$opt[] = array('value' => $k, 'label' => $v);
}
return $opt;
}
Save file and ensure that the issue is fixed.
Related
I'm trying to change the order of the steps in the magento onepage checkout. What I need to do is to move the Review step before the Payment selection.
I've looked on the internet for a solution but everything I found was to change the order in app/code/core/Mage/Checkout/Block/Onepage/Abstract.php
I've tried it, but nothing changed.
What I did was creating a file inside app/code/local/Mage/Checkout/Block/Onepage/Abstract.phpand inside this file I've changed the line 208 in:
protected function _getStepCodes()
{
return array('login', 'billing', 'shipping', 'shipping_method', 'review', 'payment');
}
what am I missing here?
(I'm using Magento 1.9.1.1)
Don't change the php code.Keep it as it is.I think let the php do his work. But show the thing you want. Go to app->design->frontend->[package-name]->default->template->checkout->onepage->progress.phtml and open and change the order accordingly. Have fun.
i'm currently working on a little extension to make it possible to adopt related products of a group product on its associated products.
It work really fine, with the exception, that only the last of the 19 related product is saves and written to the database.
I've checked my source code over and over, even with my team collegue - the code seems to be correct.
In the following i've posted the snippet with the essential parts and i hope that anyone can give me a hint or an advice to solve this problem.
Best regards
Markus
$supplyList =$product->getRelatedProductIds();
$associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);
$params = array();
$_associatedProduct = Mage::getModel('catalog/product');
$prodCount=0;
foreach($supplyList as $sup)
{
$params[$sup] = array('position'=>$prodCount);
$prodCount++;
}
foreach($associatedProducts as $prod)
{
$_associatedProduct
->load($prod->getId())
->setRelatedLinkData($params)
->save();
}
following an update for the problem mentioned in the first post.
Today it worked as it should, without changes made by myself or my collegue.
I'm not sure what the cause of the problem was (caches are disabled since last Monday) and the source was already correct implemented.
It works now and this post is solved, sadly without a solution.
best regards
In order to fix some 404s as reported by Webmaster tools, I need to add some custom URL rewrites (URL redirects) on a per-store basis to my multi-store Magento installation, but I am unable to do that: as soon as I select the "Custom" URL rewrite type from the top selector, a custom URL Rewrite edit form appears, but there are no stores selectable in "Store" dropdown list, and - since Store is a required field, Magento admin doesn't let me save the redirect.
Can anyone spread some light on this? My Magento version is 1.5.0.1, but if this is a bug, as I suspect, it might be present in other (even more recent) versions as well.
Thanks
This is a bug indeed. To fix this, apply the following patch or simply replace line 120 of your app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php with these lines.
I would suggest you don't modify the "core" file directly, but create the same folder structure in app/code/local instead, copy the core file there and edit it. Files with the same path in "local" have higher priority and will be loaded instead of those in "core" by Magento, they are also more easy to spot and eventually remove, restoring default Magento functionality, if needed in future.
app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php => app/code/local/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php
119a120,130
120: } else {
121: foreach ($stores as $i => $store) {
122: if (isset($store['value']) && $store['value']) {
123: $found = false;
124: foreach ($store['value'] as $_k => $_v) {
125: if (isset($_v['value']) && $_v['value']) {
126: array_push( $entityStores, $_v['value'] );
127: }
128: }
129: }
130: }
I have the following issue with a Magento 1.8.1 installation. I have two store views, English, which is default, and Arabic.
In the English store view if I add a product to the shopping cart I am able to modify the quantity by inputing the new quantity in the qty box and clicking Update Shopping Cart, which changes the quantity and the totals.
However, when I switch over to the Arabic store view, I can't update the quantity of any products. I input the desired quantity and press update, but the page reloads with only 1 piece of the product, and the totals are unchanged. I've tested and I've noticed that the cart only updates only for quantities over 31.
I've tried / checked the following:
This line is present in cart.phtml - getBlockHtml('formkey'); ?>
This line is present in cart.phtml - getChildHtml('form_before') ?>
There are no Javascript errors
I am using the default cart functionality, no Ajax or anything else.
I've tried replacing the cart.phtml file with the original one in the base folder, the behavior is the same.
I've tried adding the Store ID to the URL, it didn't fix the issue.
CLeared cache manually.
There are no errors in the php logs.
I've set up Manage stocks in Catalog/Inventory and reindexed, it didn't fix the issue.
Any ideas will be greatly appreciated.
Thanks,
Alex
Try to remove this code by overriding it on "local"
if (isset($params['qty'])) {
$filter = new Zend_Filter_LocalizedToNormalized(
array('locale' => Mage::app()->getLocale()->getLocaleCode())
);
$params['qty'] = $filter->filter($params['qty']);
}
from app\code\core\Mage\Checkout\controllers\CartController.php (line 183)
Create to overrride app\code\local\Mage\Checkout\controllers\CartController.php
And remove this also by overriding it on "local"
if (isset($data['qty'])) {
$cartData[$index]['qty'] = $filter->filter(trim($data['qty']));
}
from app\code\core\Mage\Checkout\controllers\CartController.php (line 428)
Create to override app\code\local\Mage\Checkout\controllers\CartController.php
Also remove this by overriding it on "local"
if (isset($params['qty'])) {
$filter = new Zend_Filter_LocalizedToNormalized(
array('locale' => Mage::app()->getLocale()->getLocaleCode())
);
$params['qty'] = $filter->filter($params['qty']);
}
from app\code\core\Mage\Checkout\controllers\CartController.php (line 327)
Create to override app\code\local\Mage\Checkout\controllers\CartController.php
I am finding some odd behavior when I try to save a product model from a script it Magento Enterprise 1.8 that has tier pricing.
Take this code for example:
// This product has a tier price
$product = Mage::getModel('catalog/product')->load(194760);
$product->setName('Changed Product Title');
$product->save();
When saving a get an exception (detailed below). However if I change nothing in the model, I do not get the exception. I have a feeling that this is due to the fact that I did not update anything so Magento does not do as much work.
// Same product, but I changed nothing and it works
$product = Mage::getModel('catalog/product')->load(194760);
$product->save();
The odd part is that I am able to save the product successfully if I am setting or modifying tier price information (pending I do not create anything that is duplicated)
// This works pending the tier price does not already exist
$mud_array = array();
$mud_array[] = array(
'website_id' => 0,
'cust_group' => 32000,
'price_qty' => 5,
'price' => 6
);
$product = Mage::getModel('catalog/product')->load(194760);
$product->setTierPrice($mud_array);
$product->save();
The exception that I am seeing is as follows:
Fatal error: Uncaught exception 'Mage_Eav_Model_Entity_Attribute_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '194760-1-0-5.0000-0' for key 'UNQ_CATALOG_PRODUCT_TIER_PRICE'' in /path/to/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php:61
So it appears that when a tier price exists in a product, and you try to change anything inside the model, it will attempt to reinsert all the tier price information.
Has anyone seen this before? Is there a way to work around this? Thanks for any help you can provide.
I had the same problem with EE 1.12, but with the "group_price" attribute. Just managed to fix the error by adding at the begging of my script
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Ok so I created a fix for this that seems to work.
In /app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Attribute/Backend/Tierprice.php there is a function called savePriceData. From what I can gather this function is responsible for determining if we need to update or insert a tier price.
There is an if block that makes this decision to update or insert based on the information coming from the $priceObject that is passed to the function.
If you are updating a tier price from the admin panel, priceObject has two values value_id and value. These fields both point to columns in the catalog_product_entity_tier_price table. This is what happens in the first part of the if block
If you are creating a new tier price from the admin panel, priceObject has all the columns from the catalog_product_entity_tier_price table (entity_id, all_groups, customer_group_id, qty, value, and website_id). Magento then takes this information and inserts it into the catalog_product_entity_tier_price table.
The actual problem was that when you save a product from a script (aka outside the admin panel) you ALWAYS get a priceObject that contains all the information for an insert. So it will always try to do the insert into the table which if it already exists causes an integrity constraint violation.
So the fix I put together for this was really quite simple. In the second part of the if block, I am doing a check to see if the tier price already is in the table and if it is, I simply do not do the insert. Here is the code:
... first part of if statement
// somehow we need to have this not happen if it already exists
$reader = $this->_getReadAdapter();
$sql = "SELECT * FROM catalog_product_entity_tier_price WHERE ";
foreach($data as $index => $value) {
$sql .= $index . ' = ' . $value . ' AND ';
}
$sql = substr($sql, 0, -4);
$search = $reader->fetchAll($sql);
if(count($search) > 0) {
// It already exists, don't do anything
} else {
$adapter->insert($this->getMainTable(), $data);
}
Obviously, you really should make sure that you copy this file to local before you make this change (or probably better yet, rewrite it in a module). This probably is not the most 100% correct "Magento way" to do this, but I really needed to get a solution for this ASAP.
I am open to better solutions than this, but I wanted to share what I found
(Note: As I am on the Enterprise Edition of Magento, I did not want to share anymore of the source than necessary since it could be a violation of our license agreement)