Hoping some one can help me with a Magento Rule - is this rule even possible
I have numerous products of numerous sizes all part of the same category.
Each product regardless of size costs £3.98 - If a buyer buys 3 products of the same category regardless of the product or size they get it for £9.99. If they buy 4 products, they get 3 of them for 9.99 but pay full price for the 4th...Every group of 3 is £9.99
I have a rule created that seems to work perfect if a Customer buys 3 / 6 / 9 items of the same product and same size...However if they mix and match it doesn't work (though they are the same category)
The rule is:
IF ALL of these conditions are TRUE:
If total quantity equals or greater than 3 for a subselection of items in cart matching ALL of these conditions:
Category is 4
I have also set the Discount Qty Step to be 3
* UPDATE *
Thanks for your reply - I have tried to implement what you suggest and have got so far as to where I get the category id of the added products. I'm unsure how to set the price the previous products so it will be an automatically discounted price
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
$itemPrice = "3.33";
foreach ($cartItems as $items) {
$product = $items->getProduct();
$prodCats = $product->getCategoryIds();
if (in_array('4', $prodCats)) {
$itemQty = $items->getQty();
}
$totalItems += $itemQty;
}
So what I want to do is apply a discount for multiple of 3's for any product that has a category_id of 4...The price will be 3.33 instead of the normal 3.99
You need event - observer approach for this, that will give you the flexibility you need. You can build an observer that catches the add-to-cart event sales_quote_add_item and put your logic there.
Following code within your observer function will point you in the right direction:
// Get products in cart:
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
$itemSku = $item->getSku();
$itemQty = $item->getQty();
}
// Added product:
$item = $observer->getEvent()->getQuoteItem();
$itemQty = $item->getQty();
$itemSku = $item->getSku();
// Change price of added product:
$item->setOriginalCustomPrice($newPrice);
Good luck!
Related
I want it to reduce the number of products in the cart from stock after the order is placed. sample: The product stock with 5 IDs is 50 pieces, if 5 orders are received from this product,I want it updated to be 50 - 5 = 45.
note:number=the quantity of the product in the current order
more detailed: There is number in the cart_product table, stock in the products table,Number of products in cart_product,Taking the number from the cart_product table and subtracting it from the stock in the product table, but i didn't succeed can you help me please
DB::table('products')
->join('products', 'products.id', 'cart_product.product_id')
->join('cart_product', 'cart.id', 'cart_product.main_cart_id')
->where(session('active_cart_id'),'=','cart_product.main_cart_id')
->orWhere('cart_product.product_id','=','products.id')
->update();
// Fetch items in the cart
$cartItems = DB::table('cart_product')
->where('main_cart_id', session('active_cart_id'))
->get();
foreach ($cartItems as $cartItem) {
// Update stocks in the "products" table
DB::table('products')
->where('id',$cartItem->product_id)
->decrement(
'AAAAA',
$cartItem->BBBBB;
);
}
I couldn't use the column names since I don't know. Keep in mind that you need to change the following texts in the code:
AAAAA => Column name of the purchased item amount in "cart_product" table.
$cartItem->BBBBB => Column name of item stock in "products" table.
For more information about increment and decrement methods, you can look at https://laravel.com/docs/9.x/queries#increment-and-decrement
it worked like this
// Fetch items in the cart
$cartItems = DB::table('cart_product')
->where('main_cart_id', session('active_cart_id'))
->get();
foreach ($cartItems as $cartItem) {
// Update stocks in the "products" table
DB::table('products')
->where('id',$cartItem->product_id)
->decrement(
'stock',
$cartItem->number
);}
I need to import 40.000 products.
These products together are generating 600.000 attribute values
There is a csv file with product info (Sku, Name, Description and Ean) and a seperate sheet with only the attributes(600K)
On each row i have:
Sku - Attribute - Value
e.g.
123 Color Green
123 Length 120
123 Size XL
456 Color White
456 Length 260
etc..
I have filtered all duplicates out which resulted in 2200 unique Attributes.
What should i Do with these attributes?
Put them all in one attributeset? Will it hurt the performance of the webshop?
And what about the attributesheet?
How should i convert the structure of the presented data so it will be usefull for for import in magent? Cause magento needs all attribute names as columnheaders?
I have tried to collect teh attribute values with VLOOKUP but run into memory problems on my MACbook Pro. Fill down one column with a formula doesn't work wit this amount of records.
Maybe there is a solution programmticly.
Thanks!
I would suggest to create product pragmatically.
Import product into a mysql table (tables) and create using magento code directly.
You can create configurable attributes and use its id when creating products.
You should think about using uRapidFlow.
While I am not a huge fan of the fact that it uses direct sql to import products, it has been around for some time and is known to be very reliable and very fast.
//add new products
$product = Mage::getModel('catalog/product');
$product->setSku($sku);
$product->setStatus(1);
$product->setName($name);
$product->setDescription($details);
$product->setShortDescription($description);
$product->setPrice(0);
$product->setTypeId('simple');
$product->setAttributeSetId(4); // enter the catalog attribute set id here
$product->setCategoryIds($categoryIds); // id of categories
$product->setWeight(1.0);
$product->setTaxClassId($taxClassId);
$product->setVisibility($visibility);
$product->setStatus($productStatus);
$product->setColor('color',$color_id); // u need to get attribute code for dropdown items
$product->setData('material', $avid);
$product->setBrand($brand);
/*$product->setStockData(
array(
'manage_stock' => 1,
'is_in_stock' => 1,
'qty' => $qty
)
);*/
// assign product to the default website
$product->setWebsiteIds(array(1,2,3,4));
try{
$product->save();
$i++;
;
}catch (Exception $e) {
echo Mage::logException($e->getMessage());
}
$id = Mage::getModel('catalog/product')->getIdBySku(trim($sku)); //get product id after create
//add dropdown items for attribute u created already, u need to make this as function to get option id before add a product
$attribute_model = Mage::getModel('eav/entity_attribute');
$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;
$attribute_code = $attribute_model->getIdByCode('catalog_product', $attribute_code);
$attribute = $attribute_model->load($attribute_code);
$attribute_table = $attribute_options_model->setAttribute($attribute);
$options = $attribute_options_model->getAllOptions(false);
foreach($options as $option)
{
if (strtolower($option['label']) == strtolower($label))
{
$optionId=$option['value'];
break;
}
}
//u need to run thru a loop to add products
I'm new in magento.
I'm wondering how I can count all products using stock quantity. For example, I have
category 1
product one - stock 10
product two - stock 5
category 2
product three - stock 10
The result of the sum of all products should be 25
Actually, I'm using
<?php
$prods = Mage::getModel('catalog/product')->getCollection();
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($prods);
$count = number_format(count($prods));
echo $count;
?>
but this counts the products without stock quantity.
Thanks for your help.
Untested but this should get you what you need…
$stockItemCollection = Mage::getModel('cataloginventory/stock_item')
->getCollection();
$stockTotal = array_sum($stockItemCollection->getColumnValues('qty'));
This should work, too. The reports collection joins together all the quote_items. But I'm not sure wether any order status is considered
$collection = Mage::getResourceModel('reports/product_sold_collection');
$collection->addOrderedQty();
// EDIT reading the question is all
$sum = 0;
foreach($collection as $product) {
$sum += $product->getOrderedQty();
}
echo $sum;
My website is build by magento system use for shopping. now I add a function about nice foreign price. for example:
if the price is $35.4 , it will be changed to $34.99;
if the price is $35.5 , it will be changed to $35.99;
code is : round(35.4) + 0.99;
now here is a question, my product has several options link 'type','colour'. and different option shows different price just as the default configurable product in magento.
in the product page: price is $1000 shows $999.99, colour red + $100 shows +$99.99
,and type big +50 shows+49.99. here the total price is 1149.97. but in shopping chat the price is round(1000 + 100 +50)+0.99 = 1149.99. so I don't know how to deal with it.
some one help me ..... waiting for your advice.
because magento final price is calculate onFly ,you shall overwrite
app/code/core/Mage/CatalogRule/Helper/Data.php
and change method to like as . (you need add to adminhtml it option or hardcode it)
public function calcPriceRule($actionOperator, $ruleAmount, $price)
{
$priceRule = 0;
switch ($actionOperator) {
case 'to_fixed':
$priceRule = min($ruleAmount, $price);
break;
case 'to_percent':
$priceRule = $price * $ruleAmount / 100;
break;
case 'by_fixed':
$priceRule = max(0, $price - $ruleAmount);
break;
case 'by_percent':
$priceRule = $price * (1 - $ruleAmount / 100);
break;
case 'my_custom_prices':
//your price rules
break;
}
return $priceRule;
}
I have a Magento order model that I create like this:
$order = Mage::getModel('sales/order')->load($orderId);
Now I want to get the order grand total including the taxes etc., but without the shipping costs. I can retrieve the grand total with $order->getGrandTotal(), but how can I exclude the shipping costs?
Thank you in advance!
$amount = $order->getGrandTotal() - $order->getShippingAmount();
Try not to over-think it. ;-)
Here is another quick method to get grand total incuding taxes and without shipping fee.
if you are dealing with the cart:
$quote = Mage::getModel('checkout/session')->getQuote();
$cartGrossTotal = 0;
foreach ($quote->getAllItems() as $item) {
$cartGrossTotal += $item->getPriceInclTax()*$item->getQty();
}
if you are dealing with an order:
$orderGrossTotal = 0;
foreach ($order->getAllItems() as $item) {
$orderGrossTotal += $item->getPriceInclTax()*$item->getQty();
}
I think
base_subtotal_incl_tax can be, so
$order->getBaseSubtotalInclTax()
There is one way more easy:
$orderValue = $order->getSubtotal();
Return the subtotal from the order, without shipping method;
Try it.