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
Related
I need the Woocommerce cart to be cleaned in case I send more than four items to it via url.
I came up with this code, but it only cleans the cart if there are already five items in it.
//in functions.php
add_filter( 'woocommerce_add_to_cart_validation', 'remove_cart_item_before_add_to_cart', 20, 3 );
function remove_cart_item_before_add_to_cart( $passed, $product_id, $quantity ) {
if( WC()->cart->get_cart_contents_count() >= 5 )
WC()->cart->empty_cart();
return $passed;
}
Another problem is that, even the code above that is not useful to me, does not work if I add multiple courses via url, as in:
https://exemple.net/cart?fill_cart=100,101,102,103,104,105,106
That is, the code in functions.php only works from the website, and not by url.
All I need is clear the cart when sending more than 4 items by url.
I prefer a solution in PHP, but a JS solution will do. Thanks for who can help me.
I found a solution using the free plugin Cart links for WooCommerce, and making a few change in its code.
I will describe below what I did:
1) To start install the plugin, this will allow you to add products using the fill_cart parameter in url (as described in my question)
2) edit the plugin file soft79-cart-links-for-woocommerce.php found at: yoursite/wp-content/plugins/soft79-cart-links-for-woocommerce/
3) go to line 141 or find the declaration of the method fill_cart
Inside the fill_cart method uncomment (or add) the code to clean the cart:
public function fill_cart( $fill_string ) {
$original_notices = wc_get_notices();
wc_clear_notices();
////Clear the cart
//WC()->cart->empty_cart(); <-- uncomment here!
Save the file. Now any new items that arrive via url must clean the cart first.
I am trying to understand the use of different columns present in magento sales_flat_order table..
this is what i have got so far...
protect_code
used to ensure the order being loaded is the correct one for the guest's cookie value, but not sure why magento sets this field for even logged in users..
magento table "sales_flat_order" field "protect_code" explanation
Cancelled, Invoice, Refunded ...
discount_canceled, discount_invoiced, discount_refunded
shipping_amount, shipping_canceled, shipping_invoiced, shipping_refunded
shipping_tax_amount, shipping_tax_refunded
subtotal_canceled.....
tax_amount.....
total_canceled....
then again repeated for base_discount_canceled...
I already know everything with base has to do with base currency and the other is to with store currency..
Not able to understand need of so many columns discount_canceled, discount_invoiced, discount_refunded
Magento can issue partial refunds, so can understand for refunded..
but for invoice, canceled it can rather have only one field
eg. invoice = true and use grandtotal, basegrandtotal fields ..
if this was a design issue than why this is present even in magento 2?
If i am missing some feature of magento which requires this, then i am more than interested to know about it ..
edit_increment
edit_increment
relation_child_id, relation_child_real_id, relation_parent_id, relation_parent_real_id
I found this in app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
public function createOrder()
..
..
$oldOrder = $this->getSession()->getOrder();
$originalId = $oldOrder->getOriginalIncrementId();
if (!$originalId) {
$originalId = $oldOrder->getIncrementId();
}
$orderData = array(
'original_increment_id' => $originalId,
'relation_parent_id' => $oldOrder->getId(),
'relation_parent_real_id' => $oldOrder->getIncrementId(),
'edit_increment' => $oldOrder->getEditIncrement()+1,
'increment_id' => $originalId.'-'.($oldOrder->getEditIncrement()+1)
);
..
..
$this->getSession()->getOrder()->setRelationChildId($order->getId());
$this->getSession()->getOrder()->setRelationChildRealId($order->getIncrementId());
But i am not sure , for what condition this code is executed
Some old orders in the database are having edit_increment as 1....
Few other fields..
adjustment_negative , adjustment_positive , ext_customer_id , ext_order_id
P.S- Using magento enterprise..
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.
For a client of mine I refactored some code that didn't work anymore. The script imports (variable) products from a CSV. That all works fine, the products and the attributes get imported and show up all complete in the backend.
The weird thing is, the products don't show up on the front-end of the website. That is, untill we save it just once from the backend (really, just pressing the save button for that product without doing anything else).
During the refactoring we found this code;
$test = new WC_Product($id);
$test->variable_product_sync();
$test = null;
This doesn't work anymore with the new WooCommerce, everything is static now. How can we implement this function now? And we are not sure this solves is though.
Ah, found it. You can dro the variable_product_sync. Make sure you set the meta _visible to 'visible' trough update_post_meta.
include_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/woocommerce/woocommerce.php' );
$product_variable = new WC_Product_Variable($product_id);
$product_variable->sync($product_id);
wc_delete_product_transients($product_id);
I have an issue. I want to show 4 related products in the product page. That is simple and I have done that. But if the product doesn't have any or has less than 4 products I want the remaining product to randomly appear in the page.
To select 4 random products first you need rewrite class that responsible for related block (or just move this file to local folder) and change logic for function that returns collection to something like next code:
$productsCollection = Mage::getResourceModel('catalog/product_collection');
$productsCollection->getSelect()->order('rand()');
$productsCollection->getSelect()->limit(4);
Hope, it will be helpful
If you're only interested in creating this functionality on the product page you can find most of the magic in Mage_Catalog_Block_Product_List_Related::_prepareData().
To fill out your related products with random products, we first need to know exactly how many random products we'll need. In this case, it's (4 - related products found):
// Existing Magento code near end of method
$this->_itemCollection->load();
// Our code
$numRandomsToGet = 4 - count($this->_itemCollection);
Then we can fetch the appropriate number of random products and add them to the collection:
// Our code
$randCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($randCollection);
$randCollection->getSelect()->order('rand()');
$randCollection->addStoreFilter();
$randCollection->setPage(1, $numRandomsToGet);
$randCollection->addIdFilter($this->_itemCollection->getAllIds(), true);
foreach($randCollection as $randProduct)
{
$this->_itemCollection->addItem($randProduct);
}
// Existing Magento code
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;
Caveat/Plug: I pulled this code from our Related Products Manager extension for Magento so there might be some fiddling external to this method that needs to get done but I don't think so. If you get stuck you can try downloading the extension and examining the code in its entirety. Or, of course, you can just use the extension as-is.