I add an item in mini-cart and I tried to get mini-cart value like price, qty, and sku in Product Detail Page and it show empty, but when I get mini-cart value in other page except Product Detail Page it show the value
anybody can help me how to get mini-cart value in Product Detail Page?
here's my code:
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cartlist = $objectManager->create('\Magento\Checkout\Helper\Cart')->getQuote()->getAllItems();
?>
<?php
foreach ($cartlist as $item) {
$productSku = $item->getSku();
$productQty = explode(".",$item->getQty());
$productPrice = explode(".",$item->getPrice());
$itemCart[] = "{item: "."'".$productSku."'".", "."price: ".$productPrice[0].", "."quantity: ".$productQty[0]."}";
$newitemCart = implode(", ",$itemCart);
}
?>
the code is in new phtml (I created a new phtml) file in <myvendor>/<theme>/Magento_Theme/templates/html/ Then I called the phtml in default.xml (<myvendor>/<theme>/Magento_Theme/layout/). Then when I get mini-cart value in other page except Product Detail Page it show the value but in Product Detail Page the mini-cart value is empty)
$custom_cart = $objectManager->get('\Magento\Checkout\Model\Cart');
$custom_cart->getQuote()->getItemsQty();
Related
my current code in sidebar.phtml
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
if($category->getId()==503){
echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('automation_tissue_processors')->toHtml();
}
?>
when I am on a page with category in breadcrumbs it works fine
Home > Instruments > automation-tissue-processors-embedders.html
the problem is when there is no category in the breadcrumbs I get a blank page
Home > automation-tissue-processors-embedders.html
this happens when I click on a product from search result
any way to fix this?
You are accesing the category>getId() on null object $category that's why it leads to blank page. Just use this code in if codition
if(!empty($category) && $category->getId()==503){
echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('automation_tissue_processors')->toHtml();
}
How to format the product view page price differently from the one from category page ( and possible others ) ?
If I change in my child theme the:
app/design/frontend/VENDOR/my_theme/Magento_Catalog/templates/product/price/final_price.phtml
The price is being changed on both pages (category and product);
I have tried several approaches but it seems that this price rendering mechanism is complicated as hell in Magento2.
Thanks!
<?php
try {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get(‘Magento\Framework\App\Action\Context’)->getRequest();
$currentPageXML = $request->getFullActionName();
echo $currentPageXML; //catalog_product_view is product detail page controller action
} catch (Exception $e) {}
?>
The above code will help you get the current area of the environment being accessed, and then you can apply a logic
if ($currentPageXML=="catalog_product_view") {
// render my custom need
} else {
// keep the actual code intact.
}
You are facing a problem because same phtml file is being used by both the catalog and product page, so a change in this file will be reflected everywhere.
I hope this will help you.
RESOLVED: In the contact controller i had function index with the page location then a separate one called function send_mail. I removed the send_mail function and moved the code up to the index function which when the email was sent or error messages thrown back it kept the url as /contact not /contact/send_mail and now the drop-down menu now works! Of course on my contact view i changed echo form_open('contact/send_email'); to echo form_open('contact');
I have built a responsive website using the Codeigniter Framework.
When the screen size shrinks to a mobile/tablet width, the navigation changes from buttons to a drop-down select menu.
I have a function in my controller called send_mail and when the user clicks the form they will receive either an error message if they filled in the form incorrect or a success message and in the url when this button is clicked the send_mail is added on the end of it.
The form does submit and all works but when testing; only when the responsive site changes to the drop-down select menu and the send_mail is added to the end of the url, you can not navigate to another page - it just stays on the same page.
At the moment i am testing and i have built the site on a localhost so unsure if it is just this or a possible solution to this?
In this post i havent added any code in (but can if it helps) as i was asking as a guidance or a suggestion why this doesn't work? Is this something to do with my media queries or drop-down as even though the send_mail is on the end it still works when it is the other widths as buttons??
CODE is below:
Is there a possible way of hiding the send_email function in the url in the routes folder when the form is submitted so it just shows http:///www.websitename/contact instead of http:///www.websitename/contact/email_send or is this something to do with the "if statement" when the user is sent back to the form?
Again everything works perfectly when the site is resized using the standard nav ul styling at other widths, just the dropdown which is hidden until it is displayed in the media query.
HTML for Select Menu (This is hidden unless mobile version)
<option value="" selected="selected">MENU</option>
<option value="Home">Home</option>
<option value="about">About</option>
<option value="testimonials">Testimonials</option>
<option value="blog">Blog</option>
<option value="contact">Contact</option>
</select>
CSS media query(MOBILE)
nav ul { display: none; }
nav select { display: inline-block; }
Jquery for Responsive Nav
send_email function in Contact Controller
public function send_email (){
$this->load->library('form_validation');
$this->form_validation->set_rules('name','Name','trim|required|htmlspecialchars|max_length[30]|xss_clean');
$this->form_validation->set_rules('email','Email Address','trim|valid_email|required|htmlspecialchars|max_length[100]|xss_clean');
$this->form_validation->set_rules('message','Message','trim|required|htmlspecialchars|xss_clean');
$this->form_validation->set_error_delimiters('<div id="errors">• ','</div>');
if ($this->form_validation->run() == FALSE) {
$data['success'] = '';
$data['page_title'] = 'Contact';
$data['content'] = 'contact';
$this->load->view('template', $data);
}else{
$data['success'] = 'The email has successfully been sent';
$data['name'] = $this->input->post('name');
$data['email'] = $this->input->post('email');
$data['message'] = $this->input->post('message');
$html_email = $this->load->view('html_email', $data, true);
//load the email class
$this->load->library('email');
$this->email->from(set_value('email'), set_value('name'));
$this->email->to('emailaddressusuallyhere');
$this->email->subject('Message from Website');
$this->email->message($html_email);
$this->email->send();
$data['success'] = 'The email has successfully been sent';
$data['page_title'] = 'Contact';
$data['content'] = 'contact';
$this->load->view('template', $data);
}
}
RESOLVED: In the contact controller i had function index with the page location then a separate one called function send_mail. I removed the send_mail function and moved the code up to the index function which when the email was sent or error messages thrown back it kept the url as /contact not /contact/send_mail and now the drop-down menu now works! Of course on my contact view i changed echo form_open('contact/send_email'); to echo form_open('contact');
I have the below code and which makes the page title more seo friendly. However I am running into the below problems.
config.noPageTitle = 1
page.headerData {
100 = TEXT
100 {
field = description
noTrimWrap = noTrimWrap = |<title>| - Example Site</title>|
}
}
If I have the field = title it displays tha page title field, however on the news single page it doesn't work as it displays the name of the page rather than the title of the aritle.
If I have the field = description the news single defaults to the article title however if I haven't put a description on one of my pages then it displays
<title> - Example Site</title>
Is there away to do if description = '' show title (if it is not a news article)?
Or is there another way I should be approaching this?
There are many samples and snippets for using tt_news title as page title.
Check for an instance this one: http://blog.chandanweb.com/typo3/display-news-title-as-page-title-in-tt_news-detail-view
How can I display the right image, title and link for a Facebook Like button in a list of products?
I do implement sucessfully the like button but it is when you navigate to the product details, you see only one product.
I ask how can i do it in the list of products, for now the image displayed on my facebook page is a generic image from the site and not the specific image of the product, the link is right.
Must the tag <meta property="og:image" content="some value"/> only be inside the head tag? I cannot use it inside the body tag?
The meta tags for the news story don't need to be on the page that is displaying the Like button. The news story will be generated from the meta tags on the page listed in the URL parameter of the Like button.
Here is an example. -
This Repeater will dynamically generate a list of products from a database with customized Like buttons:
<asp:Repeater ID="_RPT_Product" runat="server">
<HeaderTemplate><h3>Products</h3><ul class="bulleted-list"></HeaderTemplate>
<ItemTemplate><li><%# Utilities.ScrubText(((Product)Container.DataItem).ProductName) %>
</li>
<div style="padding-top:10px;">
<iframe
src="https://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.yourdomainname.com/Product.aspx%3FID%3D<%#((Product)Container.DataItem).ProductID %>%26x%3D1&send=false&layout=button_count&width=88&show_faces=false&action=like&colorscheme=light&font&height=23"
scrolling="no" frameborder="0"
style="border:none; overflow:hidden; width:88px; height:23px;"
allowTransparency="true">
</iframe></div><br />
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
This would be the code-behind on a separate Product page that dynamically renders meta tags from a product database:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Get the product meta content from the ID URL parameter.
string productName = "";
string productImageURL = "";
string productDescription = "";
int productID = 0;
if (Request.QueryString["ID"] != null)
{
productID = Convert.ToInt32(Request.QueryString["ID"]);
}
if (Request.QueryString["ID"] != null)
{
using (ProductDatabaseDataContext db = new ProductDatabaseDataContext(Config.ConnectionStrings.ProductDatabase))
{
Product select = new Product();
select = db.Products.FirstOrDefault(p =>
p.ProductID == Convert.ToInt32(Request.QueryString["ID"]));
productName = select.ProductName;
productImageURL = select.ProductImageURL;
productDescription = select.ProductDescription;
}
}
// Dynamically generate Open Graph Meta Tags for each Product:
HtmlMeta _metaTitle = new HtmlMeta();
_metaTitle.Name = "og:title";
_metaTitle.Content = "Product: " + productName;
this.Header.Controls.Add(_metaTitle);
HtmlMeta _metaURL = new HtmlMeta();
_metaURL.Name = "og:url";
_metaURL.Content = "http://www.yourdomainname.com/Product.aspx?ID=" + Convert.ToString(productID);
this.Header.Controls.Add(_metaURL);
HtmlMeta _metaImage = new HtmlMeta();
_metaImage.Name = "og:image";
_metaImage.Content = Convert.ToString(productImageURL);
this.Header.Controls.Add(_metaImage);
HtmlMeta _metaDescription = new HtmlMeta();
_metaDescription.Name = "og:description";
_metaDescription.Content = Convert.ToString(productDescription);
this.Header.Controls.Add(_metaDescription);
}
}
Note that every Like button must have a unique URL parameter, because only one set of meta content attributes can be tied to a single URL. This can be accomplished by having a unique ID parameter on your separate Product.aspx page. The "og:url" meta tag for each of your products can be the same if you just want all of the product news stories to link back to one master list page.
The Like button likes a specific URL and if it's a product the user is liking, that link really should bring users back to a description of that product and not to a completely different set of content.
What you display on that propduct page itself isn't really important (it could be the full product list if you really wanted) provided that that URL returns the same meta tags to the Facebook crawler each time
What you're trying to do could be achieved by setting up a script which serves the meta tags for each product based on URL parameters (making sure to keep the og:url tags pointing to the correct URL to generate the same tags again.
Serve those tags to the Facebook crawler and redirect other browsers wherever you want.