Magento cart error "Maximum one item to add the shopping cart." - magento-1.6

I checked the option in the system -> config -> Inventory and it's set to 1000 the Maximum Qty Allowed in Shopping Cart i can add the same product so it supplements the Qty of that product by one more, but if i add another product i get this Maximum Qty Allowed in Shopping Cart , any idea how can i fix the cart so i will be able to add more items to the cart ?
PS: i have Magento ver. 1.6.1.0
Thanks all in advance!

I would like to recommend you to do the following:
First check system -> config -> Inventory settings for all your stores. Typically users get such errors when the settings are inappropriate on different store leves.
But if you get this error adding another product, then go to the Inventory tab of your product and check whether the Maximum Qty Allowed in Shopping Cart is populated correctly.

Your error 'Maximum one item to add the shopping cart.' is quite unique and it's actually a custom error not native to Magento. I've found it in some code of a client of mine. You'll have to look for the following code blocks in a few files:
if ($cartItems >= 1) {
Mage::getSingleton('core/session')->addError($this->__('Maximum one item to add the shopping cart.'));
$this->_goBack();
return;
}
and
if ($params['product'] != $productId) {
if ($cartItems >= 1) {
$this->_getSession()->addError($this->__('Maximum one item to add the shopping cart.'));
$this->_goBack();
return;
}
}
and
if ($params['product'] != $productId) {
if ($cartItems > 1) {
Mage::getSingleton('checkout/session')->addError($this->__('Maximum one product to add the shopping cart.'));
$this->_redirect('checkout/cart');
return;
}
}
and
if ($item->getProductId() != $productId) {
if ($cartItems >= 1) {
$this->_getSession()->addError($this->__('Maximum one item to add the shopping cart.'));
$this->_goBack();
return;
}
}
You'll be likely to find them in /app/code/local/{Name}/{Module}/controllers/Checkout/CartController.php /app/code/local/{Name}/{Module}/controllers/Checkout/OnepageController.php /app/code/local/{Name}/{Module}/controllers/Sales/OrderController.php
Mentionably, {Name} is not necessarily limited to one extension... I've found it in multiple, perform a search all through all the files in /app/code/local to be sure.
In order to 'fix' it, either change the '1' in if ($cartItems > 1) { to some other (higher) number, or comment that if statement out and replace it with if(false) {.

if ($params['product'] != $productId) {
if ($cartItems > 1) {
Mage::getSingleton('checkout/session')->addError($this->__('Maximum one product to add the shopping cart.'));
$this->_redirect('checkout/cart');
return;
}
}

Related

fold() into a set Koan is not accepted

I am learning Kotlin via Koans here: https://play.kotlinlang.org/koans/Collections/Fold/Task.kt
this is my code so far:
// Return the set of products that were ordered by all customers
fun Shop.getProductsOrderedByAll(): Set<Product> {
val orderedProductsByAll = this.customers.fold(mutableSetOf<Product>()) {
collector, c -> collector.plus(c.getOrderedProducts()).toMutableSet()
}
return orderedProductsByAll
}
fun Customer.getOrderedProducts(): List<Product> =
this.orders.flatMap { o -> o.products }
Unfortunately the results is not accepted:
Fail: testGetProductsOrderedByAllCustomers: The function 'getProductsOrderedByAll' is implemented incorrectly
Any tips on what I am doing wrong here?
You have probably misunderstood the question...
Return the set of products that were ordered by all customers
means
Give me the products that are been purchased by all customer
therefore, you don't want to return "all the products that are been purchased at least 1 time by any customer", but only those that every customer have bought at least one time
At the end, "mathematically speaking" you don't want an "union", but an "intersection"... and the collector has infact an intersect method...
OT note:
also, consider that your plus method is not doing anything to the set, and your code is equivalent to:
return customers.flatMap { c -> c.getOrderedProducts() }.toSet()

Automatically increase stock after order - Prestashop

I manually manage my stocks on Prestashop. I am looking for a solution to automatically return the initial stock after a sales order.
For example, a product is ordered in two copies with an initial stock of 7. I would like the stock to remain at 7 after the order and not at 5.
Do you know a technique that would allow me to realize this automatically?
Put a Hook on Order Confirmation (displayOrderConfirmation) in a new module (you can generate one at https://validator.prestashop.com/) and check whats inside the cart then put it again in your stocks :
public function hookDisplayOrderConfirmation($params) {
$order = $params['order'];
$cart = new Cart($order->id_cart);
$products = $cart->getProducts();
foreach ($products as $product) {
$removed_qty = (int) $product['quantity'];
$past_qty = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']);
$new_qty = $removed_qty + $past_qty;
StockAvailable::setQuantity($product['id_product'], $product['id_product_attribute'], $new_qty);
}
}

multi store, manual activation account with prestashop

I use multi-store option with prestashop. I would like to pass customers in the second store to manual activation after registration.
Actually I set $customer->active = 0; in authentication.php.
all registration customer in both websites are inactive after registration.
Is there a way to set $customer->active = 0; just for one website.
I think to get shop_id but I don't know how to develop my idea.
In Prestashop 1.6 :
You can get the id_shop with the Context object.
So, I think you can do something like this :
If you know the id_shop (suppose the id_shop = 1)
if (Context::getContext()->shop->id == 1) {
$customer->active = 0;
} else {
$customer->active = 1;
}
Hope it helps.
EDIT
Updated answer to get the id_shop from context because the Customer object doesn't handle it until it's added.
RE-EDIT
In the Customer class (/classes/Customer.php) customize the add() function.
Add this line around the line 212 (after the "last_passwd_gen" declaration) :
$this->active = ($this->id_shop == 3) ? false : true;
But the best solution for you is to create an override of the function.

How can check history information for a certain customer by using scripting in NetSuite?

I want to create a Script in NetSuite which needs some history information from a customer. In fact the information I need is to know if the user has purchased an item.
For this, I would need in some way to access to the history of this customer.
Pablo.
Try including this function and passing customer's internalID and item internalID
function hasPurchasedBefore(customerInternalID, itemInternalID){
var results = [];
var filters = [];
var columns = [];
filters.push(new nlobjSearchFilter('internalidnumber', 'customermain', 'equalto', [customerInternalID]))
filters.push(new nlobjSearchFilter('anylineitem', null, 'anyof', [itemInternalID]));
filters.push(new nlobjSearchFilter('type', null, 'anyof', ['CustInvc']));
columns.push(new nlobjSearchColumn('internalid', null, 'GROUP'));
results = nlapiSearchRecord('transaction', null, filters, columns);
if (results && results.length){
return true;
}
return false;
}
Example:
var record = nlapiLoadRecord(nlapiGetRecordType(),nlapiGetRecordId());
var customerInternalID = record.getFieldValue('entity');
var itemInternalID = record.getLineItemValue('item', 'item', 1); //Gets line 1 item Internal ID
if( hasPurchasedBefore(customerInternalID, itemInternalID) ) {
//Has bought something before
}
You could use a saved search nlapiLoadSearch or nlapiCreateSearch for invoices, filtered by customer, and also reporting invoice items (or just a particular item). Using nlapiCreateSearch can be tricky to use, so I'd recommend building the saved search using the UI, then load it using nlapiLoadSeach(type, id)
This will give you an array of invoices/customers that bought your item.

count how many times a class appears in a page with codeception

I'm using Codeception to run acceptance tests and I need to count how many times a button with ".remove" class appears in one page. Such button is located inside a html table and the count depends on how many items are in the cart.
Below is the code I'm trying to use:
$I->amOnPage("/cart/");
$table = $I->grabTextFrom(".//*[#id='cart']/table");
$rows = explode("<tr>", $table);
$rcount = count($rows);
while ($rcount >= 0) {
$I->click(".remove");
$rcount--;
}
$I->see("Your shopping cart is empty.");
I know this is a bit late, but you should try $I->seeNumberOfElements as explained here:
http://codeception.com/docs/modules/WebDriver#seeNumberOfElements
$arrayProducts = $I->grabMultiple(XPATH_PRODUCTS_BOX);
$sumProducts = count($arrayProducts);
$I->comment("In category $selectCategory is total product: $sumProducts");
$I->seeNumberOfElements(XPATH_PRODUCTS_BOX, $sumProducts);
return $sumProducts;