X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Displaying Membership of the User in Invoice (https://forum.x-cart.com/showthread.php?t=77529)

siddharth.puri@wheelandba 01-19-2020 05:20 PM

Displaying Membership of the User in Invoice
 
Hi, How can I display the membership of user in the invoice? Just need to figure out how to grab the membership of the user and I will add that to the email notification.


Thanks and Regards,
Siddharth Puri

cflsystems 01-20-2020 05:43 AM

Re: Displaying Membership of the User in Invoice
 
You need to create custom module for this, best option, and add new template file to the invoice. You can position it by using @ListChild in the doc block at the beginning of the file. Just see how other templates are done.

This is a quick dirty hack. Using customer/order/invoice/parts/note.twig (and you can do that too with the theme_tweaker) if I add at the end of it


Code:

{{ this.order.profile.membership.name }}


it will show the membership name. Keep in mind this is the membership at the time of order. Changing the membership of the customer later will not affect this order's profile.
If you want to grab the current profile membership regardless of order use


Code:

{{ this.order.origProfile.membership.name }}


Also neither one will show name if there is no membership assigned to the profile in question.

siddharth.puri@wheelandba 01-28-2020 03:16 PM

Re: Displaying Membership of the User in Invoice
 
1 Attachment(s)
Hi, I added the code {{ this.order.profile.membership.name }} to the template as you suggested. (Please see image attached)

However, I do not see the membership info on the invoice even for customers who have a membership.

Please have a look.

Thanks and Regards,
Siddharth Puri

cflsystems 01-28-2020 04:14 PM

Re: Displaying Membership of the User in Invoice
 
You added it inside the "if" statement for the notes. So if the order has no customer notes nothing will show. You have to add it outside the conditional statement

siddharth.puri@wheelandba 01-28-2020 05:12 PM

Re: Displaying Membership of the User in Invoice
 
Hi I changed it now to
{##
# Order customer note
#
# @ListChild (list="invoice.base", weight="40")
#}

{% if this.order.getNotes() %}
<div class="customer-note">
<h3>{{ t('Customer note') }}:</h3>
<div>{{ this.order.getNotes()|nl2br }}</div>
</div>
{% endif %}

<div>{{ this.order.profile.membership.name }}</div>



However, still no membership is displayed.

cflsystems 01-28-2020 05:39 PM

Re: Displaying Membership of the User in Invoice
 
In that case refer to post #2 above

siddharth.puri@wheelandba 02-18-2020 07:53 PM

Re: Displaying Membership of the User in Invoice
 
Hi,

I installed a new module. How can I add template files to it? Can you please guide me in the next step.

Thanks and Regards,
Siddharth P

memoto 02-24-2020 02:53 AM

Re: Displaying Membership of the User in Invoice
 
Check the following article on how to implement template usage into the module: https://devs.x-cart.com/getting_started/how-to-apply-design-changes.html#module-pack

siddharth.puri@wheelandba 02-27-2020 05:51 PM

Re: Displaying Membership of the User in Invoice
 
Hi, I am just starting with Xcart. So I am not really confident. Do you have any example I can follow.
I assume I have to add the template file with the code <div>{{ this.order.profile.membership.name }}</div> and add that via list view to invoice.
So according to the example I have to add code
{##
#Order customer note
#
# @ListChild (list="invoice.base", weight="39")
#}
<div>{{ this.order.profile.membership.name }}</div>

However, I am not sure about the process.

Any help will be really appreciated.

cflsystems 02-28-2020 05:18 AM

Re: Displaying Membership of the User in Invoice
 
The ListChild tells the rebuild process where to inject the content of the template.
In this case it is in list "invoice.base'. So the content of your new template will show alongside with all other templates that belong to that same list.
The "weight" parameter tells the rebuild process where in the the stack within this list to inject the template. In other words "weight" it's used for sorting - sorting is in ascending order, lower to higher number.

All you have to do is to have this template and include the ListChild line then rebuild the cart - from there the process automatically will pick up on that and do whatever needs to be done.

If you do not have the ListChild directive in the template you will have to have View class that shows the template and include it there (or without the list directive your template will show when the View class is called from some other template or class).


If you include the list directive in the template file you don;t even have to have a View class to support it unless you need to show info in the template that is not already available for that view - then you need View class to pass that info to the template.

siddharth.puri@wheelandba 03-01-2020 03:48 PM

Re: Displaying Membership of the User in Invoice
 
1 Attachment(s)
Hi, Thanks for you help. I was able to display the membership when the order is completed and the invoice is generated (please see image attached).

However, I am still not able to display it in the email that is sent.
I even changed the list name an weight to list="invoice.items.head", weight="9" to display them above 'item list' in the invoice.
Is it possible to showcase it in the email sent to admin?

Thanks and Regards.

cflsystems 03-01-2020 04:37 PM

Re: Displaying Membership of the User in Invoice
 
Quote:

Originally Posted by siddharth.puri@wheelandba
Is it possible to showcase it in the email sent to admin?





You can. You have to look at the mail class(es) for this particular case and see if whatever is made available to the mail template includes membership. If not you need to make it available to the mail template in order to include it within the email send from cart to admin and/or customer.



Mail classes are separate from the rest f the logic/views.

siddharth.puri@wheelandba 03-01-2020 05:46 PM

Re: Displaying Membership of the User in Invoice
 
Hi, So I suppose I have to make changes to the classes/xlite/view/mailer.php?

And how can I make membership available to this class?

Do I declare the function this.order.profile.membership.name here?

Thanks

Ed B. 03-02-2020 12:36 AM

Re: Displaying Membership of the User in Invoice
 
Quote:

Originally Posted by siddharth.puri@wheelandba
Hi, So I suppose I have to make changes to the classes/xlite/view/mailer.php?


You would rather change classes/xlite/Core/Mailer.php, or classes/xlite/Core/Mail/AMail.php or classes/xlite/Core/Mail/Order/AOrder.php


Basically you would need to extend it to modify the function sendOrderWhatever(Order $order) and add to static::register() method the membership. )c.f. https://devs.x-cart.com/changing_store_logic/creating_custom_email_notifications.html

so that membership becomes available in appropriate twig files. However, probably you may get away with playing with the constructor in Core/Mail/AMail.php or Core/Mail/Order/AOrder.php

siddharth.puri@wheelandba 03-02-2020 03:09 PM

Re: Displaying Membership of the User in Invoice
 
Hi,

Looking at the example, I have an understanding that:

So If I am changing the function public static function sendOrderProcessedAdmin(\XLite\Model\Order $order)
{
static::register([
CODE TO REGISTER MEMBERSHIP HERE
]);

$result = static::composeOrderDepartmentMail('order_processe d', $order);

if ($result && !static::hasScheduledJob()) {
\XLite\Core\OrderHistory::getInstance()->registerAdminEmailSent(
$order->getOrderId(),
'Order is processed'
);

} elseif (static::$errorMessage) {
\XLite\Core\OrderHistory::getInstance()->registerAdminEmailFailed(
$order->getOrderId(),
static::$errorMessage
);
}
}

What needs to be entered to register membership function to make it available.

Thanks and Regards.

Ed B. 03-03-2020 12:10 AM

Re: Displaying Membership of the User in Invoice
 
Something like
Code:

'membership' => $this->order->membership,
If "$this" doesn't have the property called membership, then you could try
Code:

'membership' =>\XLite\Core\Auth::getInstance()->getProfile()->membership,

siddharth.puri@wheelandba 03-03-2020 07:57 PM

Re: Displaying Membership of the User in Invoice
 
Hi,

Thanks for your assistance. Really appreciate it.

I changed the function to
public static function sendOrderProcessedAdmin(\XLite\Model\Order $order)
{

static::register([
'membership' =>\XLite\Core\Auth::getInstance()->getProfile()->membership,
]);

$result = static::composeOrderDepartmentMail('order_processe d', $order);

if ($result && !static::hasScheduledJob()) {
\XLite\Core\OrderHistory::getInstance()->registerAdminEmailSent(
$order->getOrderId(),
'Order is processed'
);

} elseif (static::$errorMessage) {
\XLite\Core\OrderHistory::getInstance()->registerAdminEmailFailed(
$order->getOrderId(),
static::$errorMessage
);
}
}
"$this" doesn't have the property called membership so that won't work as well.


However, I still don't see the membership name in the email sent to admin when order is processed.


I am using {{ this.order.profile.membership.name }} in the view to showcase the membership name. Does that define the way we register the membership in the sendOrderProcessed Function?

Kind Regrads,
Siddharth Puri

Ed B. 03-05-2020 12:12 AM

Re: Displaying Membership of the User in Invoice
 
Since you have registered membership for the class, {{this.membership.name}} should do, if I understand correctly xc documentation (and its content is up to date/correct).

siddharth.puri@wheelandba 03-05-2020 06:37 PM

Re: Displaying Membership of the User in Invoice
 
Hi finally, I could do it. I went back to the simple solution and added
<div>{{ this.order.profile.membership.name }}</div> to the skins/common/order/invoice/parts/head.twig and it displays. i don't know why did did not work in the note.twig. Thank you everyone for their awesome support.



{##
# Invoice head
#
# @ListChild (list="invoice.base", weight="10")
#}
<table cellspacing="0" class="header">
<tr>
{{ widget_list('invoice.head') }}
</tr>
<tr>
<div>{{ this.order.profile.membership.name }}</div>
</tr>
</table>


Kind Regards


All times are GMT -8. The time now is 02:45 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.