Adding cart error to prevent going into the checkout - php

i have been working trying to create an edit order system where when an order is bellow a given state the customer can edit the order
now i have everything working by adding a reorder like link which does the exact same as reorder but creates a session which identifies that your editing an order, in order to do this for out of stock products i had to turn backorders on
however i have found a glitch, if a customer was to add 5 hats to the cart and logs off, if when they come back the item's stock qty is now 0 they can still go into the cart, naturally this is because of the backorders being enabled.
i have made a CartController to pick up adding/updates to the shopping cart and manually check if the stock is less than what's in the cart, however if the customer had the item when there was ample stock, leave and returns when it's now out of stock, they bypass these checks
one suggestion that was made by a college was that we shorten the lifetime of the cart session for registered customers, while we could do this, there is more of a problem during a sale
originally, before backorders was turned on, if this same situation occurred the "Proceed to checkout" button would be missing and you would get an error message
now i've tried fixing up a new IndexController and using $this->_getSession()->addError('Some products in your cart have gone out of stock'); but i'm not getting the same results
so how do i create an error message that will prevent the customer from going into the checkout until they have fixed up their cart

I would suggest you to make a dedicated page let's call it edit_cart. When you are redirecting to checkout, check all products and validate their qty in magento. Push them to edit_cart and let them delete out of stock products from cart. After this redirect them to checkout.

Related

How to modify quantity on checkout confirm step in opencart 2.1.0.2 version?

I am using opencart version 2.1.0.2, I wants to modify quantity of product before click on confirm button on checkout page.
Currently on opencart checkout step-6 confirm display only quantity of product, but how can I modify quantity there as same as cart page.
Thanks
You would need to write a core modification for the last checkout process step. Currently the last step (confirmation) is only the display of your entered products and their amounts.
I would not recommend changing the amount of a product at this stage. Why would you do so? Is changing the quantity in the basket not enough? Most commerce systems display a summary at the end of the checkout process. Why can't you keep with this "almost" standard?

Update WooCommerce shipping costs when selected on basket and checkout pages

I'm unsure if this is a default function of WooCommerce, but I imagine it should be. As of now, it doesn't work.
I add products to the basket and am shown the correct shipping options. I select one, but the total price on the page doesn't change.
If I click through to the checkout, the shipping method resets to the default option (ignoring the one I selected on the basket page). Selecting the correct one again still doesn't update the total price shown on the page.
Checking out and completing the transaction proves that the option chosen does get passed to the checkout process and is used for the total cost - but I can't figure out why this isn't updated on the previous pages and shown to the user, or why it resets on the checkout page.

Getting Reorder to ignore stock levels in magento

i've been tasked to create a system where a customer can edit an order before it reaches the processing stage, i figure that the easiest way is to use the cart but with some edits to it to detect that your editing the order rather than making a new one
i have been testing out theories so far and everything seem to pan out, on theory i have been trying to get to work is utilizing the same process for re-ordering to populate the cart with the previous order, however i've ran into a problem, if an item is out of stock, it wont be added and until the customer confirms the changed to their order, i can go and release what they ordered, i can store how much the customer ordered but only if the item is added to the cart
so is there a way to get magento to add items to the cart with the re-order while ignoring what stock levels are
EDIT:
i've tried removing the Try Catch in Mage_Sales_Controller_Abstract in the function reorderAction() and it's adding the items however this means also i can't catch the exception of it's if it's just a notice or if there is any other reason why it can't add the item to the cart besides not having the stock
Got it working now, the trick was to enable Backorders and also modify parts of magento to prevent sellers from exceeding stock levels when they normally order (since if an item only has 6 in stock, with backorders enabled a customer can buy 10), after that it was simply setting up a system in the cart to detect when your editing an order and only allow backordering there since all orders are checked in the warehouse

PHP:update a stock with values in the cart

I am currently working on an eCommerce website, but i need some advice regarding the stock management.
I want the shopping cart to work as follow:
CostumerA add a productO to cart with a quantity of '1'.
CostumerB tries to add the same product to their cart but with no success.
CostumerA logs out or their session expires.
CostumerB tries to add productO again and is allowed to do so since the product hasn't been added to CustomerA's cart ...
i came up with 2 solutions but neither is reliable from my point of view:
add a field 'champ' to Table product that initially have value of product.quantity but change with cart movements.
add table Cart and update it with cart movements.
as u can see both solution require lot of work.Is there a better way to implement my shopping cart.
I think a better way might be to only update if the user checks out and check stock on the product listing pages.
The downside being the following scenario:
user A adds an item to their cart
user B adds the same item to their cart
user A checks out and the item is now out of stock
user B checks out, but item is out of stock
You'll need to check stock at every point in this process and inform your users what's going on.
Tying up inventory by having a user placing it in their cart is a bad idea. If user A adds all of the available stock of one item to their cart, no one else can buy it until they either log out, or you log them out with some sort of timeout.

Shopping cart and stock management

I am currently building an ecommerce site with PHP/MySQL. Recently, I have been working on the Shopping Cart integration. The client wanted to ensure that stock was available to potential buyers, so I created a stock management system. The shopping cart works as follows:
Client adds a quantity of an item to
his cart.
Item quantity is reserved from
available stock in the database.
No one else can purchase reserved
stock.
Stock remains reserved until client
processes order - where stock is then
removed from database.
If client abandons his cart, stock remains reserved.
If another client wishes to buy an item, but only available stock is reserved by another client, then the client can steal the reserved stock if it has been inactive for 20 minutes.
My question is, what are best practices for this kind of scenario? Am I doing this correctly? The main thing is that the client does not want to sell stock that he does not have.
I am looking to have a discussion on how to improve the functionality, or what others are doing to accomplish this.
An alternative approach may be not to reserve a stock upon putting it in the shopping cart. Perform a check each time a page is reloaded, should the item be no more available, display a message like "The item you wish to buy has just been sold out. It will be available shortly". And you remove the product from the shopping cart.
Now, you absolutely have to reserve the shopping cart contents right before you initiate the payment operation, then either remove it from the stock or remove the reserve depending on the success/failure of the payment. You do it better in one code run, so that the reserve lasts as briefly as possible.
ProcessOrder ()
{
bool reserved = ReserveShoppingCartContents ();
if (reserved)
{
bool paymentStatus = ProcessPayment ();
if (paymentStatus)
RemoveShoppingCartContentsFromStock ();
else
ReleaseShoppingCartReserve ();
}
else
{
RefreshShoppingCartContents (); // Remove positions or adjust quantities
MessageBox ("Could not reserve your shopping cart contents. Please check out your selection");
}
}
The briefer your reserve lasts, the higher the chance your item will be actually sold. You minimize the possibility of a conflict: CustomerA begins with the shopping cart, the item gets reserved, CustomerB comes, sees the item is not on stock and goes away, CustomerA decides he doesn't like the price and cancels the operation. You had two potential customers but couldn't sell to either.
i do a check for the stock on every reload of the pages during the checkout proccess and redirect them to the cart page with an error message if during the process the items have been sold out.
The stock is reduced only on order confirmed
Also i restore the stock if the order is canceled.

Categories