Hello World Magento Plugin - magento

I'm new to magento & am trying to get a simple plugin working.
When a user adds a product to the basket I'd like magento to display a dialog box with some text in it.
Can anyone provide a link to a guide to this or something similar?
I'm using magento2
Thanks
EDIT:
Thanks for that,
I found a tutorial and this is what I have atm, the plugin looks to be enabled as far as I can see.
What I'm trying to get to working is a message to display when a user adds a product to the cart.
Currently the text on the add to cart button changes to 'Adding..' and hangs. How can I debug this?
Thanks for that,
I found a tutorial and this is what I have atm, the plugin looks to be enabled as far as I can see.
What I'm trying to get to working is a message to display when a user adds a product to the cart.
Currently the text on the add to cart button changes to 'Adding..' and hangs. How can I debug this or fix this?
<?php
namespace Acme\AddToCartMessage\Plugin;
use Magento\Checkout\Model\Cart\CartInterface;
use Magento\Framework\Message\ManagerInterface as MessageManager;
class AddToCartMessage{
private $messageManager;
public fucntion __construct(MessageManager $messageManager){
$this->messageManager = $messageManager;
}
public afterAddProduct(\Magento\Checkout\Model\Cart\CartInterface $cart, $result){
$this->messageManager->addNoticeMessage('Testing');
return result;
}
}

There are actually a couple ways to achieve what you're trying to do. The cleanest way would be to utilize event observers. Here's a link to their documentation - Magento 2 - Events and Observers.
A quick overview:
Create an etc/frontend/events.xml file.
Create an observer for the checkout_cart_add_product_complete event.
Inject the \Magento\Framework\Message\ManagerInterface into your observer class.
public function __construct (
\Magento\Framework\Message\ManagerInterface $messageManager
) {
$this->_messageManager = $messageManager;
}
The message manager will display a notification after the item has been added. To show a popup, you should look into M2's JS components - JavaScript Developer Guide.

Related

Magento 2.4.5: Unable to get Stripe Payment information in my observer class

With the upgrade to Magento 2.4.5 from 2.4.2, the old code in an observer class in the custom module to get information about Stripe Payment isn't working any more. It looks like Magento event sales_order_place_after isn't able to help with retrieving payment information. I tried several other events including sales_order_load_after sales_order_save_before sales_order_save_after sales_order_delete_before sales_order_delete_after checkout_submit_all_after. Below is the code snippet that calls a function by passing a Stripe payment object and an array containing order details. $stripePayment->getCard() returns null although Magento admin shows all payment information.
switch ($_payment_info->getMethod()) {
case "stripe_payments":
// We need to set the current_order in registry, as StripeIntegration script info.php uses this registry.
// Instantiate the StripeIntegration Info class after setting the registry.
$this->registry->register('current_order', $order);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$stripePayment = $objectManager->get('StripeIntegration\Payments\Block\Adminhtml\Payment\Info');
// Now, we can make the calls to retrieve the Stripe details for the Credit card.
$this->get_credit_card_payment_info($order_info, $stripePayment->getCard());
$order_info["cc_name"] = $order->getBillingAddress()->getName();
$order_info["cc_veri"] = $order->getPayment()->getTransactionId();
break;
The comments in it will help you understand that I'm using registry to store the order object for the Stripe module to use in its class. This has been working fine for the past three years until the latest Magento upgrade.

Nativescript Vue: How to create a basic layout

How can I create a basic template for all my pages?
I try to make a RadSideDrawer on all pages available. (With exception for some specific pages like login / registration etc.).
Currently I copy and past my Menu on all pages. What is the correct way handling this?
You haven't shown any code... So not sure how are you even including it. In app-root?
But you can set menu to false to disable it on some pages:
Example:
import { RadSideDrawer } from 'nativescript-ui-sidedrawer'
let sideDrawer = Application.getRootView()
sideDrawer.getViewById('sideDrawer')
sideDrawer.gesturesEnabled = false
And enable it programmatically this way.

Magento backend error: Edit user

I get an error in Magento 1.6.1.0 backend:
System -> Permissions -> Users -> Edit user
When I try to access this page nothing gets loaded into content area. Page layout and menus are displayed but the form for user editing is not.
In Firbug it throws the following error:
$("user_user_roles") is null
This line comes from
app/design/adminhtml/default/default/template/permissions/user_roles_grid_js.phtml
which has not been touched.
I did an update from 1.6.0.0 to 1.6.1.0 ... could create and edit users in the old version but I am not able to do it now. Could not find anything on the web for this error.
Please let me know if there is a fix to this.
I also got this error. Here is what I did to fix.
Open file Roles.php in app/code/core/Mage/Adminhtml/Block/Permissions/User/Edit/Tab/Roles.php and add getRowUrl() function:
public function getRowUrl($row) {
return $this->getUrl('*/*/edit');
}
Hope this helps,
Neo.

Custom BasePage causing design view to break

I was getting fed up with typing this.NavigationService.Navigate(new Uri(page.xaml, UriKind.Relative));, every time I need to navigate to a different page in my app.
So I've created a custom BasePage with a virtual to help with Navigating around my app.
The problem I have is in VS2010, if I have the source and design view open, the design just shows the windows phone background and I get some blue wiggly lines right from the top to the bottom of my xaml and messages along the lines of x isn't supported. This happens on any page that I have set up to Inherit from my custom BasePage.
However, if I run the application on my Windows Phone or in the Emmulator it will work.
Does anyone have any suggestions of what I could try to keep my Design view working whilst apply my custom base, or if I have missed something off?
A slightly cut down version of my BasePage is:
public class BasePage : PhoneApplicationPage
{
public virtual void NavigateTo(string pageName, params Tuple<string,string>[] queryString)
{
// Code to perform this.NavigationService.Navigate
}
}
EDIT 2011-08-16
Part of this base page overrides the PhoneApplicationPage's OnNavigatedTo method, in which I perform a security check to see if:
security has been enabled
User is logged in
If the security is enabled but the user is not logged in, they are immediately redirected to a Login Page.
I found this useful as I don't then have to add any code to existing or new pages to handle this, so long as they derive from the BasePage.
I wouldn't recommend using a BasePage for this. Instead, simply add your NavigateTo method in the App.xaml.cs file, as a static method.
public static void NavigateTo(string pageName, params Tuple<string,string>[] queryString)
{
// Code to perform this.NavigationService.Navigate
}
Also, remember to wrap the call to .Navigate in Dispatcher.BeginInvoke so all transition effects are properly executed.
And as a bonus tip: Don't use the designer in Visual Studio. Instead, set the 'default editor' for XAML files to be the "Source Code" editor, so the designer is never opened. This makes Visual Studio much more stable.
If you want a designer, you should get Microsoft Expression (Blend)

Magento: Fire event before the login process

After reading some posts, I'm trying to implement an observer to fire an event before the user login. I'll explain: I have a forum and a blog, using another framework, and I want the visitor to log only once: blog, forum or eshop. After that, he will be logged for other areas. For example, I am browsing the forum and I login into the forum. Then, when I open the shop, I am already logged in. And same thing for the opposite way.
It works, but just one problem: when I logged into the forum/blog and if I open the shop, I need to refresh the page to see that I am logged.
Actually, it's the same behavior as the standard Magento logout process: if you click on the link "logout" of your Magento shop, you will still see that you are logged in. There's a redirection/refresh to the homepage and then you see the message that you are logged out.
Here is my code:
app/code/community/Fanxiang/UC/etc/config.xml:
[...]
<events>
<http_response_send_before>
<observers>
<UC>
<type>model</type>
<class>Fanxiang_UC_Helper_Data</class>
<method>ucSynlog</method>
</UC>
</observers>
</http_response_send_before>
</events>
[...]
and:
app/code/community/Fanxiang/UC/Helper/Data.php
class Fanxiang_UC_Helper_Data extends Mage_Core_Helper_Abstract
{
public function ucSynlog($observer){
if(!empty($_COOKIE['Example_auth'])){
list($Example_uid, $Example_username) = explode("\t", uc_authcode($_COOKIE['Example_auth'], 'DECODE'));
list($Example_uid, $Example_username,$email) =uc_get_user($Example_username);
$customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($email);
Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
} else {
Mage::getSingleton('customer/session')->logout();
}
Mage::log(time(), null, "logfile.log");
}
}
PB: I'd like to avoid to refresh the page to see that I am logged in.
Any idea or help is welcomed!
Yoong
As you've seen http_response_send_before occurs after the HTML is generated but before it is sent by the server, so the logged in status is not visible. You need to use an event that occurs before any HTML is put together, say, controller_action_predispatch.
Here is a reference of several other possibilities
The reason for the odd behavior seems to be related to the fact that the entire framework for Magento spins up before really getting around to controllers and such. This means that your previous login state (logged out, in this case) is recorded before your code is run. It's my guess (though I haven't run through all the code) that you could reset a few session/registry variables during login to solve this problem.
If you do this, please contribute it back to Magento so that we can all share :)

Resources