I need to get applied coupon details in cart form.phtml
/app/design/frontend/Vendor/Theme/Magento_Checkout/templates/cart
In this path we have shopping cart files are there like coupon.html, form.html
In a coupon.html file we have code to get coupon
$block->escapeHtml($block->getCouponCode())
How to get this coupon detail in other phtml file form.phtml
In block you can use the following code
$getCouponObj = $block->getLayout()
->createBlock('Magento\Checkout\Block\Cart\Coupon');
echo $getCouponObj->getCouponCode(); //applied coupon code
echo $getCouponObj->getAmount(); //applied coupon amount
Related
Background: Added some new columns in oc_product_description (I added some key product features and alternative name for ebay listing, so I can generate the product data into a template to use on ebay listings, whilst keeping and using the code on the opencart website..)
Problem: that when I save the product in opencart it deletes the data I just entered into the table, because it uses a Delete and then Insert function (by the looks of it?) in admin/model/catalog/product.php approx line 140. Which uses the $data['product_descriptions'] array which comes about in admin/controller/catalog/product.php approx line 765.. but here there are 3 possibilities.. either from the post or from a get function, or a new array..
I added hidden fields to the admin/view/catalog/product_form.php but what's going on here doesn't make it through to the table in the end..
I also added the new fields to the getProductDescriptions() function and directly to the $data array just as the other fields were already..
Please don't send me off to look up MVC models..Please help!!!
The problem was: that I had used the wrong name and value in the hidden fields..I obviously wasn't giving it much thought when I merely wrote:
<input type="hidden" name="name_ebay" value="<?php echo $entry_name_ebay; ?>">
In actual fact what was required was:
<input type="hidden" name="product_description[<?php echo $language['language_id']; ?>][name_ebay]" value="<?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['name_ebay'] : ''; ?>">
I hope this post has offered some reminders or hints concerning Adding Your Own Fields to Opencart's Product Description Table, and using them in the admin
Take note mostly of:
i) use of language id in the view
ii) the delete, insert (instead of update) in model
iii) the change from post to $data array in controller
Furthermore, I did notice that the delete line,
$this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
Seems to delete the record with this product id?? but without regard to language id?.. I'll have to look into whether this deletes the translated versions on a multi-lingual site of the products in the product_description table..?
I am looping some specific products on the home page but unable to generate the ADD TO CART URL in magento 2
How to generate ADD TO CART URL when displaying products in loop.
I know it's been a year since this has been touched on, but as I've just done what has been requested, I thought that I may post my solution to help others.
The other answers will work, but only for simple products, where no further input is required (e.g. selecting options). When using getAddToCartUrl(), Magento first checks if the products requires any options to be selected; if it does, then it will simply supply the URL to the product page instead.
To skip all of these checks and directly obtain the add to cart URL, then make use of the Magento\Checkout\Helper\Cart helper instead. If you are within a .phtml file, then this can be utilised simply by calling $this->helper:
$cartHelper = $this->helper('Magento\Checkout\Helper\Cart');
From there, you can generate the add to cart URL via getAddUrl(), ensuring you pass the product object as the parameter:
echo $cartHelper->getAddUrl($product)
For it to fully work, you must have a hidden field for the form key as described in the other answers, and if the product in question has compulsory options to choose from (e.g. a configurable product), then make sure you include those fields as well, otherwise you will get redirected to the product page itself, with a message informing the user that options are required.
The excellent solution is to use
$cartHelper = $this->helper('Magento\Checkout\Helper\Cart');
and after that
echo $cartHelper->getAddUrl($product);
this give add to cart URL every time
(for a simple product, for a simple product with custom options etc)
use following to generate add to cart URL in magento2:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$listBlock = $objectManager->get('\Magento\Catalog\Block\Product\ListProduct');
$addToCartUrl = $listBlock->getAddToCartUrl($product);
Add your button code into form with form key.. It will work
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$listBlock = $objectManager->get('\Magento\Catalog\Block\Product\ListProduct');
$addToCartUrl = $listBlock->getAddToCartUrl($product);
<form data-role="tocart-form" action="<?php echo $addToCartUrl; ?>" method="post">
<?php echo $block->getBlockHtml('formkey')?>
<button type="submit"
title="Add to Cart"
class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
You can generate "add to cart" url by following code:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$listBlock = $objectManager->get('\Magento\Catalog\Block\Product\ListProduct');
$addToCartUrl = $listBlock->getAddToCartUrl($_product);
With Zend Framework 1.10 I'm having a list with articles and an search field.
When typing something in the searchfield and hit the search button it generates me the following url:
https://example.org/products?category=12&no=
On the result of the searchpage you'll find the products matching to the search field.
If there are more than 10 products with the search attribute, there is a next button. For this next button im using the following code to generate the url, which will sadly not extend the already passed arguments (category and no).
<a href="<?php echo $this->url(array('page' => $this->next)); ?>">
<?php echo $this->translate('NextPage'); ?> >
It will redirect me on https://example.org/products
How to add the already passed GET argument from the form?
You can store the GET parameters from the search in the session so when you are requesting with the next url, you can retrieve the parameters previously entered in the search form.
I created a new attribute (delivery) for my Magento shop and I'd like to show this attribute right after the product price on the product page. How can I do that?
I tried to add echo $_product->getdelivery() at view.phtml but my attribute showed up in the next line and not next to the price.
Try adding your code to catalog/product/price.phtml
else you can add css to .price-box but this would change in many places as price-box is used in many places
Better to add a class in price.phtml to price-box. Give the new class float left and add your div next to it. :)
On the categories page Where all the products are listed in rows and each complete row is a link to that product details page.
In that row I have created a textfield and a submit button but the product details link is also working on the textfield which I does not want.
When I click in the textfield for writing something in it, it redirects me to the product details page and I am unable to write something in the textfield.
So How will I handle it so that I could write some value in textfield?
This is just because of zen cart default code to redirecting user in case of clicking product row.
yo can change default behavior by two ways :
Use JavaScript/JQuery
you can use below code to prevent default action while someone click on textbox
<script>
$(".sortTextBox").click(function(event) {
event.preventDefault();
});
</script>
Manually change code in PHP file
you need to change product listing code in categories.php file located in admin folder of zencart.
Or, since you're changing the way the admin interface works, you could expand your changes to also remove the action that allows clicking on that table-row to be a quick access link to the details of that product (which is where editing of that product's information is normally handled).
For example, the onclick event in these code snippets would need to be removed:
echo ' <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . zen_href_link(FILENAME_CATEGORIES, zen_get_path($categories->fields['categories_id'])) . '\'">' . "\n";
and
echo ' <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . zen_href_link($type_handler , 'page=' . $_GET['page'] . '&product_type=' . $products->fields['products_type'] . '&cPath=' . $cPath . '&pID=' . $products->fields['products_id'] . '&action=new_product' . (isset($_GET['search']) ? '&search=' . $_GET['search'] : '')) . '\'">' . "\n";
And then you'd have to use the (e) edit button to gain access to the actual normal product edit screen, instead of the luxury of clicking anywhere on the row.