Need to update custom option value in shopping cart page - magento

I have a small problem with my shopping cart page.
In my shopping cart have these fields.
Quantity
Product description. (like 1 product $27)
My problem is,
If, I update the the quantity of my shopping cart item. For example, I will update 1 quantity as 3 quantity. And need to change the product description also. From 1 product $27 to 3 product $81.
This my sample code:
<?php foreach ($_options as $_option) : ?>
<?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
<?php //if($ii > 2) { ?>
<dt><?php echo $this->htmlEscape($_option['label']) ?></dt>
<dd style="padding-left:0px;" <?php if (isset($_formatedOptionValue['full_view'])): ?> class="truncated"<?php endif; ?>>
<?php $license_val = $_formatedOptionValue['value']; ?>
I get the option value from backend by using this $_formatedOptionValue['full_view']. So only, I much confused.
Now, I am using custom option for the product description. I need to update the custom option value. Is there any possible? Please help me to solve this problem.
Thanks

Isn't it much simpeler to retrieve the qty and the subtotal and echo these values in a translate string, you already have the data after the update for the items.
$this->__('%s product %s', $qty, $subtotal)

Its so simple just override your checkout controller and then edit updateCheckoutPost function for update custom option value, with price.
Add this code only in updateCheckoutPost function 100% working.
you need cart items id's, item's product id, qty or options array of particular product.
foreach($_POST['item_ids'] as $update_product_id){
$product = Mage::getModel('catalog/product')->load($_POST['product_ids'][$update_product_id][0]);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$params = array(
'product' => $_POST['product_ids'][$update_product_id][0],
'qty' => $_POST['cart'][$update_product_id]['qty'],
'options' => $_POST['option'][$update_product_id]);
$cart->updateItem($update_product_id,$params);
$cart->save();
}

Related

Magento 2: Switch the price for 'Sold' label after product is out of stock

I'm trying to to switch the price for a 'Sold' label on the product page of products that are out of stock.
If a product is sold out, the price should be hidden and in its stead should be a 'Sold' label.
I figured out that the price is placed in catalog_product_view.xml and it calls upon the vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml file, but I could not figure out where and how to bring in a condition to check whether product is sold out or not.
Can someone help here?
Thanks in advance.
Yuan
As I understand you have two parts to this issue
1) Hide price on Product-detail page if product is Out-of-stock
Prices are defined in vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml
called at class: Magento\Catalog\Pricing\Render and method: _toHtml()
You can override the method using DI to below
protected function _toHtml()
{
/** #var PricingRender $priceRender */
$priceRender = $this->getLayout()->getBlock($this->getPriceRender());
if ($priceRender instanceof PricingRender) {
$product = $this->getProduct();
if ($product instanceof SaleableInterface && $product->isAvailable()) {
$arguments = $this->getData();
$arguments['render_block'] = $this;
return $priceRender->render($this->getPriceTypeCode(), $product, $arguments);
}
}
return parent::_toHtml();
}
$product->isAvailable() is the new condition that we have added
2) Show Sold label
outofstock label is shown by default, but if you still want to show create your block & template in vendor/magento/modul-catalog/view/frontend/layout/catalog_product_view.xml
and $product->isAvailable() function to check product's availability
Hope this helps
Hiding price for out of stock products in Magento 1.
RWD Theme
app/design/frontend/rwd/template/catalog/product/view.phtml
Change
<div class="price-info">
<?php echo $this->getPriceHtml($_product); ?>
<?php echo $this->getChildHtml('bundle_prices') ?>
<?php echo $this->getTierPriceHtml() ?>
</div>
To:
<?php if($_product->isSaleable()): ?>
<div class="price-info">
<?php echo $this->getPriceHtml($_product); ?>
<?php echo $this->getChildHtml('bundle_prices') ?>
<?php echo $this->getTierPriceHtml() ?>
</div>
<?php endif; ?>
Default Theme:
\app\design\frontend\base\default\template\catalog\product\view\type\default.phtml
Change
<?php echo $this->getPriceHtml($_product) ?>
To:
<?php if($_product->isSaleable()): ?>
<?php echo $this->getPriceHtml($_product) ?>
<?php endif; ?>
OR
Hiding price for out of stock products in Magento 2.
On admin page, Click on Stores, then under the Setting section, choose Configuration.
In this page, you find the Inventory section under Catalog. Expand the Stock Options section and you can start to set the custom status of the product.
Before coming to the Out of stock product section, you need to enter this field.
Set Items’ Status to be in Stock When Order in Canceled: You choose YES when you want to return items to your stock if an order is canceled.
Decrease Stock When Order is Placed: if you want to adjust the quantity on hand when the order is placed, you choose Yes
Then we can come to the part that allows you to display or disable the product out of stock in Magento 2.
You want to display the product out of stock, you set the Display Out of Stock Products section is Yes. In contrast, set No if you want to disable it.

Magento Retail Store and Wholesale with Different Prices

Hey I was wondering about magento Retail/Wholesale capabilities.
The main store will be for normal customers (retail) and they see normal prices but for wholesalers they need to login and see wholesale prices?
I don't want normal visitors to see wholesale prices.
Is that possible?
Assign product price as customer groups after that use this code on list or view page, you will see product different price on both side same and equal to admin price.
<?php $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if($groupId ==1 || $groupId ==""){?>
<?php if($product->getSpecialPrice()){?>
<?php echo "$".$rprice = number_format($product->getPrice(),2); ?> </div>
<?php }else{?>
<?php $product->setCustomerGroupId($groupId);
echo "$".$price = number_format($product->getPriceModel()->getFinalPrice(1, $product),2); ?>
<?php } ?>
</div>
<?php if($product->getSpecialPrice()){ echo "Special Price $".number_format($product->getSpecialPrice(),2);?>
<?php } ?>
<?php }else{echo "$".$price = number_format($product->getPriceModel()->getFinalPrice(1, $product),2); }
?>
for create customer group check this link:
http://www.magentocommerce.com/knowledge-base/entry/customer-groups

How to show the value of an attribute in shopping cart?

I added an attribute 'items' having input type textbox in admin.I want to show the value of that attribute in shopping cart.For that i have added this code in template/checkout/cart/sidebar-top.phtml which is below:
<?php
$productId = $_item->getId();
$productInfo = Mage::getModel("catalog/product")->load($productId);
echo $productInfo->getAttributeText('product_type');
?>
but when i am adding this above code showing
Fatal error: Call to a member function getId() on a non-object
if anyone knows this,please help me out.thanks!
Use the below code
$productId = $_item->getProduct()->getId();
$productInfo = Mage::getModel("catalog/product")->load($productId);
echo $productInfo->getAttributeText('product_type');
Are you talking about custom option or simple attribute?
For Simple attribute (text) and if you are on product page try belo code:
<?php $_item = $this->getItem()?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php echo $_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product); ?>
If you are not on the product page then you can use the below code, load the product by sku and get your attribute value
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku());
echo $product->getResource()->getAttribute('attribute_code')->getFrontEnd()->getValue($product);

How to add a product to it?

<?php foreach($this->getItems() as $_item): ?>
<?php echo $this->getItemHtml($_item) ?>
<?php endforeach ?>
the code is form cart.phtml if i want to add a product into $this->getItems() which from a specified category then output it? how do i do? thank you
i should know what information of the product, then i can put it into $this->getItems() then loop out the information?
The way to accomplish this would be to add the item to your cart using either method below.
Adding a Product to the Cart via Querystring read more
/path/to/app/checkout/cart/add?product=[id]&qty=[qty]
Add product to cart programmatically (read more)
`
$params = array(
'product' => 23,
'qty' => 2,
);
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product');
$product->load(23); // load product id 23
$cart->addProduct($product, $params);
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
`

I want to display the product options value in Magento Product Page

I want to display the product options value in a Magento Product Page. I tried this code:
<?php echo $_product->getAttributeText('color'); ?>
but the options are not showing up.
If you are on the actual product view paghe you can use a helper to get what you want:
echo $_helper->productAttribute($_product, $_product->getColor(), 'color');
or
echo $_helper->productAttribute($_product, $_product->getData('attribute_code'), 'attribute_code');
Alternatively you can try this:
$_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product);
you can this one,
<?php $attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getColor();?>

Resources