@@ -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 ' );
0 commit comments