Magento 2 : How to set product name and product price in custom email template? - magento2

I want to ask how can we set values of product name and product price in my custom email template.

$product_id = 'get id';
$model = Mage::getModel('catalog/product') //getting product model
$_product = $model->load($product_id); //getting product object for particular product id
$name = $_product->getName(); //product name
$price = $_product->getPrice(); //product's regular Price
This the way to get name and price. Now use $name and $price like this.
echo $name;
echo $price;

Related

How to add notice on magento 2 checkout, on street address field for billing and shipping

I want to add notice on street address field, on magento 2 checkout page. I tried adding it in: using layout process
<?php
namespace Pawan\Notice\Model\Checkout;
class LayoutProcessorPlugin
{
/**
* #param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
* #param array $jsLayout
* #return array
*/
public function afterProcess(
\Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
array $jsLayout
) {
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['street']['children'][1]
['notice'] = __('This is my custom notice.');
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['billingAddress']['children']['billing-address-fieldset']['children']['street']['children'][1]
['notice'] = __('This is my custom notice.');
return $jsLayout;
}
}
it added only for shipping address but not billing can any one tell me how to add my billing address section under payment method
If need find exact place of tags just print layout process and add notice to particular tag
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/extranotice.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Simple Text Log'); // Simple Text Log
$logger->info('Array Log $jsLayout'.print_r($jsLayout, true)); // Array Log
checked on log file based on that I added for street
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['street']['children'][0]
['notice'] = __('No PO Box');

Catalog Price Rule Magento 2

I have created a custom module in Magento 2. In which i want to show some banners, Countdown timer and extra details on product page, also label or text on category page. for this i extended the catalog sales rule module. Added some extra field according to my requirements. Now i want to show get all those products ids on which sale rule has applied with all other details like Top Banner, Countdown timer according to sale etc.
my Block Code is
<?php
namespace Custom\Sales\Block;
class Flash extends \Magento\Framework\View\Element\Template
{
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory $ruleFactory,
array $data = []
) {
$this->_ruleFactory = $ruleFactory;
parent::__construct($context, $data);
}
public function getCatalogeRuleId()
{
$catalogRuleCollection = $this->_ruleFactory->create()
->addFieldToFilter('is_active',1);
// return $catalogRuleCollection;
$resultProductIds = [];
foreach ($catalogRuleCollection as $catalogRule) {
$productIdsAccToRule = $catalogRule->getMatchingProductIds();
// echo json_encode($productIdsAccToRule); exit;
$websiteId = $this->_storeManager->getStore()->getWebsiteId();
foreach ($productIdsAccToRule as $productId => $ruleProductArray) {
if (!empty($ruleProductArray[$websiteId])) {
$resultProductIds[$productId] = $catalogRule->getData();
}
}
return $resultProductIds;
}
}
}
Now when i print my array i get only one sale rule data , however i have created 3 different sales

How can I get a subtotal by looping. Using SugarCRM CE 6.5.13

I am trying to get a total from the rows returned for the selected opportunity.
When a opportunity is selected each product they have purchased and its price is listed. I am trying to use the price for each purchased product to get a subtotal for all sales made with that opportunity.
Here is the code I have:
function total(&$focus, $event, $arguments)
{
$total = 0;
foreach ($this->bean->Product_Sales['sales_price_c'] as $entry) {
$total += unformat_number($entry['sales_price_c']);
}
$this->bean->ss->assign('total_sales_c', format_number($total));
}
Example of how rows are returned:
[Product_Name_Field] [Product_Price_Field] [Sales_Person_Field] [Etc_Field]
Only qty(1) Product sold per returned row.
What am I doing wrong?
Thanks in advance.
Okay I figured it out!!!!
This is File view.detail.php in Custom/Module/Opportunities/Views/
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.detail.php');
class OpportunitiesViewDetail extends ViewDetail {
function OpportunitiesViewDetail(){
parent::ViewDetail();
}
function display() {
$account = new Opportunity();//var = new ModuleName() in singular form
$account->retrieve($_REQUEST['record']);//This grabs the record
$contacts = $account->get_linked_beans('opportunities_op_ps_product_sales_1','Contact');
//this uses the get_linked_beans(Param 1 is the linked var name found in the vardefs ,Param 2 is the name of the object you are creating. The name can be anything you like.)
// loop through the created associations to get fields.
foreach ( $contacts as $contact ) {
$total += $contact->sales_price_c;//add the value of each sale to the variable
}
//populate the field you want with the value in the $total var
echo "
<script>
var total = '$total';
$(document).ready(function(){
$('#total_sales_c').after(total); });
</script>";
parent::display();
}
}
?>
Hopefully this will help others.

Woo-commerce Variable Regular and Sale price

I am trying to display the regular and sale price of a variable product. I know it can be achieved from get_post_meta( $post->ID, '_regular_price', true); but it isnt working in variable products only a simple product.
I looked into the classes and also saw that woocommerce updates the post meta of _regular_price itself when storing a variable product price.
Is there anything I am missing?
Thanks
The best code for solve this is:
#Step 1: Get product varations
$available_variations = $product->get_available_variations();
#Step 2: Get product variation id
$variation_id=$available_variations[0]['variation_id']; // Getting the variable id of just the 1st product. You can loop $available_variations to get info about each variation.
#Step 3: Create the variable product object
$variable_product1= new WC_Product_Variation( $variation_id );
#Step 4: You have the data. Have fun :)
$regular_price = $variable_product1 ->regular_price;
$sales_price = $variable_product1 ->sale_price;
If you don't have any variation in your product then, you can simple get product price using product ID like:-
add_action('init', 'test');
function test() {
global $woocommerce;
$product = new WC_Product(268);
echo $product->get_price();
}
If product have variation and each variation have different price then need to get price using variation ID.
That's because variable product is not keeping any price information itself but it is the parent of another kind of child posts named "product_variation" each having their own price and variation information. So if you want to do something on price of variable products in a WP_Query loop you have to filter your loop through post_type => 'product_variation' and then you can access their parent id from their post_parent property for getting other related information of those variable products variations such as name, description, images, ...
Here is an example:
$query = new WP_Query(array(
'post_type' => 'product_variation', // <<== here is the answer
'posts_per_page' => 5,
'post_status' => 'publish',
'orderby' => 'meta_value_num',
'meta_key' => '_price',
'order' => 'asc',
));
while ($query->have_posts()) {
$query->the_post();
$pid = $query->post->ID;
$parent = $query->post->post_parent;
$price = get_post_meta($pid, '_price', true);
$regular_price = get_post_meta($pid, '_regular_price', true);
$sale_price = get_post_meta($pid, '_sale_price', true);
$title_product = get_the_title($parent);
$title_variation = get_the_title($pid);
echo "$title_variation: $price <br />";
}

Is it possible to find the Group ID or Name of logged-in user in Moodle?

Is it possible to find the Group/Grouping ID of logged-in user in Moodle 1.9?
In my Moodle Course there are three different Groups. I needed the ability to dynamically change the a href of a link on a webpage resource based on a User's Group Enrollment Key. This is what I did:
<div class="enrolment-key" style="display:none;">
<?php
// Grab current User's group from Database By ID
$sqlGROUPMEMBERS = "SELECT * FROM mdl_groups_members WHERE userid='$USER->id'";
// Put Query in new Varible
$resultGROUPMEMBERS = mysql_query($sqlGROUPMEMBERS);
// While $row = group id of user
while($row = mysql_fetch_array($resultGROUPMEMBERS)){
$groupID = $row["groupid"];
}
// Grab Enrolment Key by the Group ID
$sqlGROUP = "SELECT * FROM mdl_groups WHERE id=$groupID";
// Put Query in new Varible
$resultENROLMENTKEY = mysql_query($sqlGROUP);
// While $row = group enrolment key for that user
while($row = mysql_fetch_array($resultENROLMENTKEY)){
echo $row["enrolmentkey"];
}
?>
</div>
<script>
$(document).ready(function(){
var baseURL = "https://www.surveymonkey.com/s/";
var endURL = $('.enrolment-key').html();
$(".survey-link").attr("href", baseURL + endURL);
});
</script>
<a class="survey-link">Link</a>
There probably is a better way to do this, but its fine for a Noob like me.