Magento 2 Success.phtml output order values - magento

We're having some issues with Magento 2 where we're unable to output the order values in our checkout code. Here's our code:
<!---- Onefeed Tracking Code ---->
<?php
//-------------------------------------------
// GET MAGENTO ORDER VALUES FOR TRACKING CODE
//-------------------------------------------
$orderId = $block->escapeHtml($block->getOrderId());
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($orderId);
$total = $order->getGrandTotal();
?>
<script type="text/javascript" language="javascript">
var of_ssid = 'xxxx';
var cs = '<?php echo $total ?>';
var oi = '<?php echo $orderId; ?>';
var it = 1;
</script>
<script type="text/javascript" language="javascript" src="https://tracking.onefeed.co.uk/t.js"></script>
<noscript>
<img border="0" src="https://tracking.onefeed.co.uk/ProcessProductCheckout.ashx?of_ssid=xxxx&cs=<?php echo $total ?>&it=1&oi=<?php echo $orderId; ?>" />
</noscript>
<!---- End Onefeed Tracking Code ---->
Any ideas how we can output the data without having to create a module in Magento 2?

This part of your code is definately working (just checked):
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($orderId);
$total = $order->getGrandTotal();
?>
...
<?php echo $total ?>
Since I don't know which Block functions you are relying on it's impossible to say for sure, but I'm guessing $orderId = $block->escapeHtml($block->getOrderId()); does not return a valid order id.
I'm not sure if you should use objectManager though. There is quite a discussion about when and how to use it on the stackexchange:
https://magento.stackexchange.com/questions/117098/magento-2-to-use-or-not-to-use-the-objectmanager-directly

Related

add blog picture to user profile page in joomla contact page

I want to add the article's pictures before the articles titles in the contact (user profile page ) like so:
Also, I have created an ovveride into a template html/com_contact/contact
and I have added this code but it gives a warning:
"Notice: Undefined property: stdClass::$images"
and no image.
Code:
/ Create a shortcut for params.
$images = json_decode($this->item->images);
$introImage = $images->image_intro;
?>
<?php if ($this->params->get('show_articles')) : ?>
<div class="contact-articles">
<ul class="nav nav-tabs nav-stacked">
<?php foreach ($this->item->articles as $article) : ?>
<li>
<?php echo JHtml::_('link',
JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article-
>catid, $article->language)), htmlspecialchars($article->title, ENT_COMPAT,
'UTF-8')); ?>
<?php echo $introImage; ?>
</li>
How can I get this fixed?
i have fixed it by using this cod ;
// Create a shortcut for params.
$article_id = $article->id; // get article id
//aticle_id = JFactory::getApplication()->input->get('id'); // get article
id
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('images'))
->from($db->quoteName('#__content'))
->where('id = '. $db->Quote($article_id));
$db->setQuery($query);
$result = $db->loadResult();
$intro_image = json_decode($result)->image_intro;
//var_dump($intro_image);
//echo $intro_image;
echo "<img src=\"".$intro_image."\" alt=\"icon\" >";

Add php code in Gantry 5 template header

I am using Gantry 5 template and I want to add php code in the header. I set some variables using php and access them in the script tag. For example
<?php
$id = $user->id;
$name = $user->username;
?>
<script>
var id = '<?php echo $id; ?>';
var name = '<?php echo $name; ?>';
</script>
I want to add the above code in head of Gantry 5 template. In we just add the code in index.php but this mechanism is different in Gantry 5. How this code can be added?

magento how to get Json Config by product id

I am in need to get the Json Config by product id or sku in the product listing page for a particular category.
I can see that getJsonConfig is decalred in Product options block where only one particular product is showing thats why it can show Json Config without saying the product id. But I am in product list page.
Is there any way to get it like below?
$this->getJsonConfig($productId);
$this->getJsonConfig()
The method is part of
class Mage_Catalog_Block_Product_View
and it calls
/* #var $product Mage_Catalog_Model_Product */
$product = $this->getProduct();
public function getProduct()
{
if (!Mage::registry('product') && $this->getProductId()) {
$product = Mage::getModel('catalog/product')->load($this->getProductId());
Mage::register('product', $product);
}
return Mage::registry('product');
}
So to use it ( in any other page ) you have to set product in the block instance as below :
Mage::register('product', $_product); // add the product object in the registry
$block = Mage::getBlockSingleton('Mage_Catalog_Block_Product_View'); // Instantiate the product view block
echo $block->getJsonConfig();
I found a simple solution for configurable product view page.
Hope that will help.
if ($_product->isConfigurable())
{ $block1 = Mage::app()->getLayout()->createBlock('catalog/product_view');
$block1->setProduct($_product);
$configPrice = $block1->getJsonConfig(); //var_dump( $config = $block->getJsonConfig`enter code here`() );
$block2 = Mage::app()->getLayout()->createBlock('catalog/product_view_type_configurable');
$block2->setProduct($_product);
$config = $block2->getJsonConfig();
}
<?php if ($_product->isConfigurable()): ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $configPrice ?>);
</script>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $config ?>);
</script>
<?php endif; ?>

Google Affiliate Integration with Magento 1.7

So maybe you guys can help me out here, im trying to integrate googles tracking pixel for their Google Affiliate program. Im using the following code from here http://www.studio1909.com/2009/10/16/google-affiliate-network-conversion-tracking-pixel-magento-ecommerce/ However, after going back and forth with google they aren't so excited about the way the code from the above link is printing out the data when it comes to configurable products.
<!--Start Google Affiliate Integration-->
<?php
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$order = Mage::getModel('sales/order')->load($lastOrderId);
foreach ($order->getAllItems() as $item) {
$productArray[] = array(
"product_sku" => $item->getSku(),
"product_magento_id" => $item->getProductId(),
"product_name" => $item->getName(),
"product_qty" => $item->getQtyOrdered(),
"product_price" => $item->getPrice(),
"product_discount_amount" => $item->getDiscountAmount(),
"product_row_price" => $item->getPrice() - $item->getDiscountAmount(),
);
};
?>
<?php
$_totalData = $order->getData();
$_subtotal = $_totalData['subtotal'];
$_orderID = $_totalData['increment_id'];
?>
<img src="https://clickserve.cc-dt.com/link/
order?vid=KVENDORID&oid=<?php echo "$_orderID"; ?>&amt=<?php echo "$_subtotal"?>&prdsku=<?php foreach ($productArray as $key) {echo $key['product_sku']."^";};
?>&prdnm=<?php foreach ($productArray as $key) {echo $key['product_name']."^";};
?>&prdqn=<?php foreach ($productArray as $key) {echo $key['product_qty']."^";};
?>&prdpr=<?php foreach ($productArray as $key) {echo $key['product_price']."^";};
?>&prcatid=<?php foreach ($productArray as $key) {echo "your-product^";};
?>" width=1 height=1>
<!--End Google Affiliate Integration-->
This is the end result
<!--Start Google Affiliate Integration-->
<img src="https://gan.doubleclick.net/gan_conversion?advid=MYID&event_type=transaction&oid=10000XXXX&amt=19.0000&fxsrc=USD&prdsku=DVT2756CH CHAR M^DVT2756CH CHAR M^&prdnm=DaVinci 1952 In Charcoal T-Shirt^DaVinci 1952 In Charcoal T-Shirt^&prdqn=1.0000^1.0000^&prdpr=19.0000^0.0000^&prcatid=4425^4427^" width=1 height=1>
<!--End Google Affiliate Integration-->
So the question is there a way to edit the code above so it just echoes the main configurable product without the simple product.
Thanks!
One good place to look at this is the template for displaying the order items:
app/design/frontend/base/default/template/sales/order/items.phtml
and the code for the loop is:
<?php $_items = $_order->getItemsCollection(); ?>
<?php $_index = 0; ?>
<?php $_count = $_items->count(); ?>
<?php foreach ($_items as $_item): ?>
<?php if ($_item->getParentItem()) continue; ?>
So this can be a good way to get what you need.

in one foreach call second foreach! codeigniter

hier is the problem:
in codeigniter in controller I have next code:
$query_not_voted = "SELECT * FROM photos WHERE p_id NOT IN (SELECT distinct p_id FROM p_votes where u_id = ".$this->session->userdata('u_id').") LIMIT ".$this->db->escape_str($segment_url).", ".$config['per_page'];
$q = $this->db->query($query_not_voted);
$data['myphotos'] = $q->result_array();
foreach($data['myphotos'] as $key=>$val)
{
$query_g = "SELECT * FROM users WHERE u_id = (SELECT u_id FROM p_votes WHERE p_id = ".$val['p_id'].")";
$q_2 = $this->db->query($query_g);
$data['allvotess'] = $q_2->result_array();
$query_u = "SELECT * FROM users WHERE u_id = ".$val['u_id']." LIMIT 0, 5";
$q_1 = $this->db->query($query_u);
$data['author'] = $q_1->result_array();
}
So now I have $data['myphotos'] and this is can be outputted in view with next codes:
<?php foreach ($myphotos as $keys => $myphoto){ ?>
<div id="voteblock">
<div id="voteleft">
<img src="<?php echo base_url().$myphoto['p_thumb']; ?>" />
</div>
<?php } ?>
but how can I output $data['allvotess'] in last foreach loop?
I tried to do same, but didn't work out.
Then I tried to push the results inside $data['myphotos'] and no good result!
So What I'm Doing???
Just need someone to help me with foreachloop insite foreachloop!!!
For a week I just can't do, I can even pay for solution right now!!!
I posted also at codeingiter forum, but they say it's easy hier is link
Generally in views I use the more semantic way to write foreach and if statements, and I'll also illustrate a tiered foreach loop...
$array1 = array(1,2,3,4);
$array2 = array(1,2,3,4);
$array3 = array(1,2,3,4);
$second_array[] = $array1;
$second_array[] = $array2;
$second_array[] = $array3;
so now we have $second_array that is a multi-dimensional array...
$data->second_array = $second_array;
$this->load->view('your/view',$data);
in a view file...
<? foreach($second_array as $array): ?> //<--start first foreach loop
<div>do some stuff</div>
<? foreach($array as $array_item): ?> //<--start second foreach loop, inside the first
<div>do some other stuff for every item in $array</div>
<? endforeach; ?> //<--end first foreach
<? endforeach; ?> //<--end second foreach

Resources