I am trying to subscribe to some events in Shopware for a plugin - the most important is "Customer Updates" (or new customers).
I am able to successfully capture the event:
// Customer (user) update
$this->subscribeEvent(
'Shopware\Models\Customer\Customer::postUpdate',
'onTriggerCustomer'
);
In my "onTriggerCustomer" function:
public function onTriggerCustomer(Enlight_Hook_HookArgs $arguments)
{
// Do something
$subject = $arguments->getSubject();
// log this, Logger is a logging function..
$this->Logger($subject);
}
I have tried endless attempts to get the contents of $arguments but with no luck, all I really need is the customerID.
Any help in trying to work out what arguments are available would be great?
getId();
get('id');
var_export(anything, true);
Everything just returns null/nothing..
Based on your code snippet, you can get the customer id as follow:
$this->subscribeEvent(
'Shopware\Models\Customer\Customer::postUpdate',
'postUpdateCustomer'
);
....
public function postUpdateCustomer(Enlight_Event_EventArgs $arguments) {
$customer = $arguments->get('entity');
$customerId = $customer->getId();
}
Related
There is a view OrderWizard module view in suitecommerce core code.It has methods similar to below(not the exact code, not pasting for proprietary issues).
I have created the extension and calling OrderWizard's method from the extension.
**setAddr: function(xxx, xxxx) {
this.model.setAddress(xxx, xxxx, xxxx);
return this;
}
renderView: function() {
if (!this.isActiveVal()) {
return this;
}
}**
Extension class:
**define(
'TEST.PaymentValidation.PaymentValidation'
, [
'OrderWizard.xxxxx.xxxxx'
]
, function (
OrderWizardAddress
)
{
'use strict';
return {
mountToApp: function mountToApp (container)
{
_.extend(OrderWizardAddress.prototype,
{
setAddressExt: function setAddressExt() {
{
OrderWizardAddress.prototype.setAddr.apply(this, arguments);
}
}
});
_.extend(OrderWizardAddress.prototype,
{
renderExt: function renderExt() {
{
OrderWizardAddress.prototype.renderView.apply(this, arguments);
}
}
});
OrderWizardAddress.prototype.setAddressExt();
OrderWizardAddress.prototype.renderExt();
}
};
});**
when calling the renderExt method,
Cannot read property 'isActiveVal' of undefined TypeError: Cannot read property 'isActiveVal' of undefined. Eventhough isActiveVal is available in OrderWizard view.
When calling the setAddressExt
I'm getting 'this is undefined'.
Can someone help me what I'm doing wrong here. What is the best way to call the suitecommerce core codes method from the extension.I guess I'm not passing the actual context(.apply(this) of the OrderWizard view.
Figured out the solution.Basically two independent views have to communicate among each other and display the value.
Payment view and Billing view are two different views. Based on the payment method selected, default billing address needs to selected.Used Backbone's event queue aggregator approach to solve this problem. when the payment method is selected, a publisher sends a message to subscriber. If the payments method is Invoice, publisher publishes the message to subscriber which triggers a method to select the default Billing address.
To add new method from the extension, used the javascript prototype and to add codes to the existing method, used the underscore's wrap method
Please how can I get the receipt number on Stripe with c#
My image :
https://www.casimages.com/i/191231053006538388.png.html
Maybe with a Session ID ?
You'd access the Charge object and it's a field on that resource.
You say you're using Checkout. So the Charge is under session.payment_intent.charges.data[0]. It requires a little digging to get it but it's all there. I'd suggest that when you receive the event as part of fulfilling the order etc, retrieve the Session(stripe.com/docs/api/checkout/sessions/retrieve) and expand "payment_intent". Then session.PaymentIntent.Charges.Data[0].ReceiptNumber is the value you're looking for.
static void CheckoutSessionReceiptEmail()
{
var service = new Stripe.Checkout.SessionService();
var session = service.Get(
"cs_test_nHUZtpUvaI80YAKGgCMGyeHfjQ6nMtUhVLeVpowWsgpfyGujccGxnAuJ",
new Stripe.Checkout.SessionGetOptions
{
Expand = new List<string> { "payment_intent" }
}
);
Console.WriteLine(session.PaymentIntent.Charges.Data[0].ReceiptNumber);
}
I have a custom module that uses Kentico API (DocumentHelper) to update certain fields of my document and then publish but I do not want it to trigger the event handlers that are linked to my document page type. I tried adding comments to .Publish("admin_edit") hoping that I can catch it from the WorkflowEventargs parameter but the VersionComment property always return null. Is there a way to accomplish this in Kentico?
update field:
var document = DocumentHelper.GetDocument(documentID, tree);
var workflowManager = WorkflowManager.GetInstance(tree);
var workflow = workflowManager.GetNodeWorkflow(document);
if (workflow != null)
{
document.CheckOut();
document.SetValue("SomeFIeld", "some value");
document.Update(true);
document.CheckIn();
document.Publish("admin_edit");
}
event handler:
public override void Init()
{
WorkflowEvents.Publish.After += Publish_After;
}
private void Publish_After(object sender, WorkflowEventArgs e)
{
if (!string.IsNullOrEmpty(e.VersionComment) &&
e.VersionComment.Contains("admin_edit"))
return;
}
You always get null for Version information, because that is related to the 'Page versioning' events, specially for 'SaveVersion'. You can find more about that on this link. If you expand 'Properties' you will see which properties are populated for the specific event. In your case, you can try something like this, to add your message for last version and then check for that comment on 'Publish_After' event, see code bellow:
var document = DocumentHelper.GetDocument(documentID, tree);
var workflowManager = WorkflowManager.GetInstance(tree);
var workflow = workflowManager.GetNodeWorkflow(document);
if (workflow != null)
{
document.CheckOut();
document.SetValue("SomeFIeld", "some value");
document.Update(true);
document.CheckIn(versionComment: "admin_edit");
document.Publish();
}
and then, in event handler, take last version and check for comment like this:
if (e.PublishedDocument?.VersionHistory?.Count > 0)
{
var lastVersion = e.PublishedDocument.VersionHistory[0] as VersionHistoryInfo;
if (lastVersion.VersionComment.Equals("admin_edit"))
{
return;
}
}
NOTE: In case that you have a lot of concurrent content editors, there is a chance that your last version is not version from API (someone changed content and saved it right after your API call made change). There is a low chance for that, but still is possible. If this is something that you will use often, you must take it in consideration. This code is tested for Kentico 11.
I know there is option in kentico admin setting to stop the sending notification email. but I want to check this in the code for my customization. so could you please suggest me where should I get the code in kentico.
Setting in kentico
Please refer to the official documentation.
You need to use SettingsKeyInfoProvider:
SettingsKeyInfoProvider.SetValue("CMSSettingName", "SiteName", value);
Leave out the site name parameter if you want to set it globally.
The settings names you are looking for are CMSStoreSendOrderNotification and CMSStoreSendPaymentNotification.
You can find more settings by querying the DB:
SELECT * FROM [CMS_SettingsKey] where keyname like '%cmsstoresend%'
If you are looking to intercept an action when a notification is being sent, you can use Global events for the EmailInfo object like this:
[assembly: RegisterModule(typeof(GlobalEventsModule))]
public class GlobalEventsModule : Module
{
public GlobalEventsModule() : base (typeof(GlobalEventsModule).Name)
{
}
protected override void OnInit()
{
base.OnInit();
EmailInfo.TYPEINFO.Events.Insert.Before += Insert_Before;
}
private void Insert_Before(object sender, ObjectEventArgs e)
{
// executed before an e-mail is inserted into DB
var email = (EmailInfo)e.Object;
}
}
To cancel the execution in code you can call Cancel() method (although you might get exceptions in this case - you have to test for yourself in your scenario):
private void Insert_Before(object sender, ObjectEventArgs e)
{
var email = (EmailInfo)e.Object;
e.Cancel();
}
This will also work only if you are using Email queue (which is highly recommended anyway) and will be executed for all outgoing e-mails, not just notifications.
Using the CMS.Ecommerce library you can check these settings through the API
SiteInfoIdentifier sii = new SiteInfoIdentifier(SiteContext.CurrentSiteID);
bool sendOrderNotificationEmail = CMS.Ecommerce.ECommerceSettings.SendOrderNotification(sii);
If you wanted to set them programmatically you would have to use the SettingsKeyInfoProvider
SettingsKeyInfoProvider.SetValue("CMSStoreSendOrderNotification ", false);
I am getting the following error when i try to update the item's name in the sharepoint
document library. The item is of type document set and its default values is loaded using javascript. In the Item added event we are updating with the new changed item's name value. But in the item.update() code statement i am getting following error.
The File CZY14389 has been modified by domain\username on current date.
Please provide your commens on resolving this.
You cannot change the name of a sharepoint document like that. You need to "move it".
Item.Update();
Item.File.MoveTo(Item.ParentList.RootFolder.Url + "/" + newFileName, false);
Item.File.Item["FileRef"] = newFileName;
Item.File.Update();
before you update item name and call item.update(), can you try to refresh your item like this:
item = item.ParentList.GetItemById(item.ID);
item.name = "xyz";
item.update();
this can sometimes happen in event handler. the problem is the updation process in the event handler is not as the same of the workflow. In event handler for updating you have to use the followitn steps. Dont use Item.Update() as in workflow.
Follow the steps:
• call and disable event firing before your code with : base.EventFiringEnabled = false;
•update your item by calling item.systemUpdate(false);
•enable event firing with : base.EventFiringEnabled = true;
Disable event firing and call your update code, dont forget to enable event firing.
HandleEventFiring handleEventFiring = new HandleEventFiring();
handleEventFiring.DisableHandleEventFiring();
try
{
item.Update();
//if item.Update doesnt work then use(For me item.update worked only on my local not on prod then i used the below)
//item.SystemUpdate(false)
}
finally
{
handleEventFiring.EnableHandleEventFiring();
}
public class HandleEventFiring : SPItemEventReceiver
{
public void DisableHandleEventFiring()
{
//obsolete
//this.DisableEventFiring();
this.EventFiringEnabled = false;
}
public void EnableHandleEventFiring()
{
//obsotete
//this.EnableEventFiring();
this.EventFiringEnabled = true;
}
}