Skip to content

Commit b450218

Browse files
committed
Merge pull request #1 from blakefinney/master
Expose user-supplied properties. Fix bug in transaction code.
2 parents 1d9996c + 676f281 commit b450218

6 files changed

Lines changed: 98 additions & 113 deletions

File tree

12.9 KB
Binary file not shown.
13.2 KB
Binary file not shown.

app/code/community/TriggeredMessaging/DigitalDataLayer/Model/Page/Observer.php

Lines changed: 92 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,25 @@ public function _isConfirmation() {
166166
public function getVersion() {
167167
return $this->_version;
168168
}
169-
169+
170170
public function getPurchaseCompleteQs() {
171171

172-
$orderId = $this->_getCheckoutSession()->getLastOrderId();
173-
if ($orderId) {
174-
$order = $this->_getSalesOrder()->load($orderId);
175-
$email = $order->getCustomerEmail();
176-
}else{
177-
$email = $user->getEmail();
178-
}
172+
$orderId = $this->_getCheckoutSession()->getLastOrderId();
173+
if ($orderId) {
174+
$order = $this->_getSalesOrder()->load($orderId);
175+
$email = $order->getCustomerEmail();
176+
}else{
177+
$email = $user->getEmail();
178+
}
179179
$qs = "e=" . urlencode($email);
180180

181-
182-
if($orderId){
181+
if($orderId){
183182
$qs = $qs . "&r=" . urlencode($orderId);
184-
}
183+
}
185184

186185
return $qs;
187186
}
188-
187+
189188
public function getUser() {
190189
return $this->_user;
191190
}
@@ -300,7 +299,7 @@ public function _setPage() {
300299
$this->_page['category'] = array();
301300
if (Mage::registry('current_category')) {
302301
// There must be a better way than this
303-
$this->_page['category']['primaryCategory'] = Mage::registry('current_category')->getData()['name'];
302+
$this->_page['category']['primaryCategory'] = Mage::registry('current_category')->getName();
304303
}
305304
// $this->_page['category']['subCategory1'];
306305
$this->_page['category']['pageType'] = $this->_getPageType();
@@ -331,6 +330,8 @@ public function _setUser() {
331330
$this->_user = array();
332331
$user = $this->_getCustomer();
333332
$user_id = $user->getEntityId();
333+
$firstName = $user->getFirstname();
334+
$lastName = $user->getLastname();
334335

335336
if ($this->_isConfirmation()) {
336337
$orderId = $this->_getCheckoutSession()->getLastOrderId();
@@ -351,7 +352,12 @@ public function _setUser() {
351352
if ($user_id) {
352353
$profile['profileInfo']['profileID'] = (string) $user_id;
353354
}
354-
// $profile['profileInfo']['userName'];
355+
if ($firstName){
356+
$profile['profileInfo']['userFirstName'] = $firstName;
357+
}
358+
if ($lastName){
359+
$profile['profileInfo']['userLastName'] = $lastName;
360+
}
355361
if ($email) {
356362
$profile['profileInfo']['email'] = $email;
357363
}
@@ -455,40 +461,65 @@ public function _getProductModel($product) {
455461
$product_model['productInfo']['productName'] = $product->getName();
456462
$product_model['productInfo']['description'] = strip_tags($product->getShortDescription());
457463
$product_model['productInfo']['productURL'] = $product->getProductUrl();
458-
$product_model['productInfo']['productImage'] = $product->getImageUrl();
459-
$product_model['productInfo']['productThumbnail'] = $product->getThumbnailUrl();
460-
// $product_model['productInfo']['manufacturer'];
464+
465+
//Check if images contain placeholders
466+
if(!($product->getImage()=="no_selection")){
467+
$product_model['productInfo']['productImage'] = $product->getImageUrl();
468+
}
469+
if(!($product->getThumbnail()=="no_selection")){
470+
$product_model['productInfo']['productThumbnail'] = $product->getThumbnailUrl();
471+
}
472+
//Attributes
461473
if ($product->getWeight()) {
462-
$product_model['productInfo']['size'] = $product->getWeight();
474+
$product_model['attributes']['weight'] = floatval($product->getWeight());
463475
}
464-
476+
try{
477+
$attributes = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getAttributeCollection();
478+
foreach($attributes as $attr){
479+
$infoLocation = 'none';
480+
$attrCode = $attr->getAttributecode();
481+
if($attrCode==='color'||$attrCode==='manufacturer'||$attrCode==='size'){
482+
$infoLocation = 'productInfo';
483+
} elseif($attr->getData('is_user_defined')) {
484+
$infoLocation = 'attributes';
485+
}
486+
if($infoLocation!=='none'){
487+
if($attr->getData('frontend_class')==='validate-number'){
488+
$product_model[$infoLocation][$attrCode] = floatval($attr->getFrontend()->getValue($product));
489+
} elseif($attr->getData('frontend_class')==='validate-digits'){
490+
$product_model[$infoLocation][$attrCode] = intval($attr->getFrontend()->getValue($product));
491+
} else {
492+
if($product->getAttributeText($attrCode)){
493+
$product_model[$infoLocation][$attrCode] = $product->getAttributeText($attrCode);
494+
}
495+
}
496+
}
497+
}
498+
} catch(Exception $e){
499+
}
465500
// Category
466-
$categories = $this->_getProductCategories($product);
467-
if (isset($categories[0])||isset($categories[1])||isset($categories[2])) {
468-
$product_model['category'] = array();
469-
470-
if (isset($categories[0])) {
471-
$product_model['category']['primaryCategory'] = $categories[0];
472-
}
473-
if (isset($categories[1])) {
474-
$product_model['category']['subCategory1'] = $categories[1];
475-
476-
// Delete if subcategory is a duplicate of the primary category
477-
if (isset($categories[0]) && $categories[0]===$categories[1]) {
478-
unset( $product_model['category']['subCategory1'] );
479-
}
480-
}
481-
if (isset($categories[2])) {
482-
$product_model['category']['subCategory2'] = $categories[2];
483-
484-
// Delete if subcategory is a duplicate of previous subcategory
485-
if (isset($categories[1]) && $categories[1]===$categories[2]) {
486-
unset( $product_model['category']['subCategory2'] );
487-
}
488-
}
489-
490-
// $product_model['category']['productType'];
491-
}
501+
// Iterates through all categories, checking for duplicates
502+
$allcategories = $this->_getProductCategories($product);
503+
if($allcategories){
504+
$catiterator = 0;
505+
$setCategories = array();
506+
foreach($allcategories as $cat){
507+
if($catiterator==0){
508+
$product_model['category']['primaryCategory'] = $cat;
509+
$catiterator++;
510+
511+
} else {
512+
if(!in_array($cat, $setCategories)){
513+
$product_model['category']["subCategory$catiterator"] = $cat;
514+
$catiterator++;
515+
}
516+
}
517+
array_push($setCategories, $cat);
518+
}
519+
if($product->getTypeID()){
520+
$product_model['category']['productType'] = $product->getTypeID();
521+
}
522+
}
492523

493524
// Price
494525
$product_model['price'] = array();
@@ -712,7 +743,7 @@ public function _getLineItems($items, $page_type) {
712743
}
713744

714745
// $litem_model['linkedProduct'] = array();
715-
// $litem_model['attributes'] = array();
746+
// $litem_model['attributes'] = array();
716747

717748
array_push($line_items, $litem_model);
718749
}
@@ -827,8 +858,12 @@ public function _setCart() {
827858
if ($this->_extractShippingMethod($quote)) {
828859
$cart['price']['shippingMethod'] = $this->_extractShippingMethod($quote);
829860
}
830-
$cart['price']['priceWithTax'] = (float) $quote->getShippingAddress()->getTaxAmount() + $quote->getBaseSubtotal(); // TODO: Find a better way
831-
$cart['price']['cartTotal'] = (float) $quote->getGrandTotal();
861+
if ($quote->getShippingAddress()->getTaxAmount() && $quote->getBaseSubtotal()){
862+
$cart['price']['priceWithTax'] = (float) $quote->getShippingAddress()->getTaxAmount() + $quote->getBaseSubtotal(); // TODO: Find a better way
863+
}
864+
if($quote->getGrandTotal()){
865+
$cart['price']['cartTotal'] = (float) $quote->getGrandTotal();
866+
}
832867
// $cart['attributes'] = array();
833868
if ($cart['price']['basePrice']===0.0&&$cart['price']['cartTotal']===0.0&&$cart['price']['priceWithTax']===0.0) {
834869
unset($cart['price']);
@@ -965,14 +1000,15 @@ public function _setTransaction() {
9651000
$transaction['total']['shippingMethod'] = $this->_extractShippingMethod($order);
9661001

9671002
// Get addresses
968-
$shippingId = $order->getShippingAddress()->getId();
969-
$address = $this->_getOrderAddress()->load($shippingId);
970-
$billingAddress = $order->getBillingAddress();
971-
$shippingAddress = $order->getShippingAddress();
972-
$transaction['profile'] = array();
973-
$transaction['profile']['address'] = $this->_getAddress($billingAddress);
974-
$transaction['profile']['shippingAddress'] = $this->_getAddress($shippingAddress);
975-
1003+
$transaction['profile'] = array();
1004+
if($order->getBillingAddress()){
1005+
$billingAddress = $order->getBillingAddress();
1006+
$transaction['profile']['address'] = $this->_getAddress($billingAddress);
1007+
}
1008+
if($order->getShippingAddress()){
1009+
$shippingAddress = $order->getShippingAddress();
1010+
$transaction['profile']['shippingAddress'] = $this->_getAddress($shippingAddress);
1011+
}
9761012
// Get items
9771013
$items = $order->getAllItems();
9781014
$line_items = $this->_getLineItems($items, 'transaction');

app/design/frontend/base/default/template/triggeredmessaging/digital_data_layer.phtml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
$transaction = $mage->getTransaction();
2121
$events = $mage->getEvents();
2222
?>
23-
24-
25-
26-
27-
28-
2923
<?php
3024
try {
3125
// Extract things only available within template (and not model)
@@ -38,8 +32,6 @@
3832
} catch(Exception $e) {}
3933
?>
4034
<!-- W3C Digital Data Layer Start -->
41-
42-
4335
<script type="text/javascript">
4436
try {
4537
window.digitalData = window.digitalData || {};
@@ -67,19 +59,14 @@ try {
6759
<!-- W3C Digital Data Layer End -->
6860
<?php endif; ?>
6961

70-
7162
<?php if ($triggered_messaging_script_enabled) :?>
72-
7363
<!-- Triggered Messaging Script Start -->
7464
<?php if ($triggered_messaging_website_id) :?>
7565
<script defer="defer" async="async" src='//d81mfvml8p5ml.cloudfront.net/<?php echo $triggered_messaging_website_id; ?>.js'></script>
76-
7766
<?php if ($mage->_isConfirmation()) :?>
7867
<?php $pcqs = $mage->getPurchaseCompleteQs(); ?>
7968
<img src="//d1f0tbk1v3e25u.cloudfront.net/pc/<?php echo $triggered_messaging_website_id; ?>/?<?php echo $pcqs; ?>" />
8069
<?php endif;?>
81-
82-
8370
<?php else: ?>
8471
<script type="text/javascript">
8572
console.log("You have enabled the Triggered Messaging script from the Magento Admin Configuration Panel, but have not supplied a website ID. Please contact hello@triggeredmessaging.com if you would like some assistance.");
@@ -88,4 +75,4 @@ console.log("You have enabled the Triggered Messaging script from the Magento Ad
8875
<!-- Triggered Messaging Script End -->
8976
<?php endif;?>
9077

91-
<?php } catch (Exception $e) {} ?>
78+
<?php } catch (Exception $e) {} ?>

var/package/TriggeredMessaging_DigitalDataLayer-0.3.0.xml renamed to package.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<package>
3-
<name>w3c-digital-data-layer-by-triggered-messaging</name>
4-
<version>0.3.0</version>
3+
<name>W3CDigitalDataLayerByTriggeredMessaging</name>
4+
<version>0.3.4</version>
55
<stability>stable</stability>
66
<license uri="http://opensource.org/licenses/apachepl.php">Apache Software License v2</license>
77
<channel>community</channel>
@@ -29,9 +29,9 @@ https://github.com/TriggeredMessaging/digitalDataMagentoExtension/issues</descri
2929
- Minimum prices of grouped and bundled products can be extracted.&#xD;
3030
- Output of debug data can now be controlled through admin configuration panel.</notes>
3131
<authors><author><name>Muhammed Miah</name><user>momiah1234</user><email>muhammed.miah@triggeredmessaging.com</email></author><author><name>Triggered Messaging</name><user>tmsdemo</user><email>demostore@triggeredmessaging.com</email></author><author><name>Mike Austin</name><user>tmsdemo</user><email>dev@triggeredmessaging.com</email></author></authors>
32-
<date>2014-09-02</date>
33-
<time>10:24:15</time>
34-
<contents><target name="magecommunity"><dir name="TriggeredMessaging"><dir name="DigitalDataLayer"><dir name="Block"><file name="Ddl.php" hash="134766e2a49c3ecfbf03d1025dd41e8b"/></dir><dir name="Helper"><file name="Data.php" hash="5a6e19225e7db056946c95b1477e5c18"/></dir><dir name="Model"><dir name="Container"><file name="Ddl.php" hash="cc9dcd8cf4e460a01c242ac675ce5634"/></dir><file name="Observer.php" hash="26e0dcfc7a19d5310e44e004c144c23e"/><dir name="Page"><file name="Observer.php" hash="166bc19f18eca2e2c041617245e29096"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="8b98dee82241e0b69661bf4699cba334"/><file name="cache.xml" hash="1b6658073a8126cd655cb18109559f49"/><file name="config.xml" hash="a29f9fb1250c40a8d973e470ffab46ac"/><file name="system.xml" hash="a72e032172f1a6b05ba969415bf33f63"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="triggeredmessaging"><file name="digital_data_layer.phtml" hash="085b6aca6f250111d916b3b7dc0442d6"/><file name="digital_data_layer_after_content.phtml" hash="6ee383b4d2011fd7e718b2930b7cd95d"/></dir></dir><dir name="layout"><dir name="triggeredmessaging"><file name="digital_data_layer.xml" hash="3c58b9faec1d9c63e1fb0a3fcc35a2d8"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TriggeredMessaging_DigitalDataLayer.xml" hash="cfc3b1bff54f3e1f224f120e536bc411"/></dir></target></contents>
32+
<date>2014-10-01</date>
33+
<time>05:55:56</time>
34+
<contents><target name="magecommunity"><dir name="TriggeredMessaging"><dir name="DigitalDataLayer"><dir name="Block"><file name="Ddl.php" hash="134766e2a49c3ecfbf03d1025dd41e8b"/></dir><dir name="Helper"><file name="Data.php" hash="5a6e19225e7db056946c95b1477e5c18"/></dir><dir name="Model"><dir name="Container"><file name="Ddl.php" hash="cc9dcd8cf4e460a01c242ac675ce5634"/></dir><file name="Observer.php" hash="26e0dcfc7a19d5310e44e004c144c23e"/><dir name="Page"><file name="Observer.php" hash="eb6dbe1c03fc786769c25857f807afc8"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="8b98dee82241e0b69661bf4699cba334"/><file name="cache.xml" hash="1b6658073a8126cd655cb18109559f49"/><file name="config.xml" hash="a29f9fb1250c40a8d973e470ffab46ac"/><file name="system.xml" hash="a72e032172f1a6b05ba969415bf33f63"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="triggeredmessaging"><file name="digital_data_layer.phtml" hash="61001c0d1d3478f9db8366f4386da754"/><file name="digital_data_layer_after_content.phtml" hash="6ee383b4d2011fd7e718b2930b7cd95d"/></dir></dir><dir name="layout"><dir name="triggeredmessaging"><file name="digital_data_layer.xml" hash="3c58b9faec1d9c63e1fb0a3fcc35a2d8"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TriggeredMessaging_DigitalDataLayer.xml" hash="cfc3b1bff54f3e1f224f120e536bc411"/></dir></target></contents>
3535
<compatible/>
3636
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
3737
</package>

var/package/TriggeredMessaging_DigitalDataLayer-0.3.1.xml

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)