17
17
18
18
namespace Meta \BusinessExtension \Helper ;
19
19
20
+ use Magento \Catalog \Api \Data \ProductInterface ;
20
21
use Magento \Catalog \Api \ProductRepositoryInterface ;
21
22
use Magento \Customer \Api \CustomerMetadataInterface ;
23
+ use Magento \Framework \Exception \LocalizedException ;
22
24
use Magento \Store \Model \StoreManagerInterface ;
23
25
use Magento \Checkout \Model \Session as CheckoutSession ;
24
26
use Magento \Quote \Model \Quote ;
@@ -50,57 +52,57 @@ class MagentoDataHelper extends AbstractHelper
50
52
/**
51
53
* @var StoreManagerInterface
52
54
*/
53
- private $ storeManager ;
55
+ private StoreManagerInterface $ storeManager ;
54
56
55
57
/**
56
58
* @var CustomerMetadataInterface
57
59
*/
58
- private $ customerMetadata ;
60
+ private CustomerMetadataInterface $ customerMetadata ;
59
61
60
62
/**
61
63
* @var ProductRepositoryInterface
62
64
*/
63
- private $ productRepository ;
65
+ private ProductRepositoryInterface $ productRepository ;
64
66
65
67
/**
66
68
* @var ProductIdentifier
67
69
*/
68
- private $ productIdentifier ;
70
+ private ProductIdentifier $ productIdentifier ;
69
71
70
72
/**
71
73
* @var CheckoutSession
72
74
*/
73
- private $ checkoutSession ;
75
+ private CheckoutSession $ checkoutSession ;
74
76
75
77
/**
76
- * @var Quote
78
+ * @var Quote|null
77
79
*/
78
80
private $ quote ;
79
81
80
82
/**
81
83
* @var CustomerSession
82
84
*/
83
- private $ customerSession ;
85
+ private CustomerSession $ customerSession ;
84
86
85
87
/**
86
88
* @var CategoryRepositoryInterface
87
89
*/
88
- private $ categoryRepository ;
90
+ private CategoryRepositoryInterface $ categoryRepository ;
89
91
90
92
/**
91
93
* @var PricingHelper
92
94
*/
93
- private $ pricingHelper ;
95
+ private PricingHelper $ pricingHelper ;
94
96
95
97
/**
96
98
* @var AddressFactory
97
99
*/
98
- private $ addressFactory ;
100
+ private AddressFactory $ addressFactory ;
99
101
100
102
/**
101
103
* @var RegionFactory
102
104
*/
103
- private $ regionFactory ;
105
+ private RegionFactory $ regionFactory ;
104
106
105
107
/**
106
108
* MagentoDataHelper constructor
@@ -173,23 +175,13 @@ public function getLastName(): string
173
175
return $ this ->customerSession ->getCustomer ()->getLastname ();
174
176
}
175
177
176
- /**
177
- * Return currently logged in users' Date of Birth.
178
- *
179
- * @return string
180
- */
181
- public function getDateOfBirth (): string
182
- {
183
- return $ this ->customerSession ->getCustomer ()->getDob ();
184
- }
185
-
186
178
/**
187
179
* Return the product by the given sku
188
180
*
189
181
* @param string $productSku
190
- * @return \Magento\Catalog\Api\Data\ ProductInterface | bool
182
+ * @return ProductInterface | bool
191
183
*/
192
- public function getProductBySku ($ productSku )
184
+ public function getProductBySku (string $ productSku )
193
185
{
194
186
try {
195
187
return $ this ->productRepository ->get ($ productSku );
@@ -199,10 +191,12 @@ public function getProductBySku($productSku)
199
191
}
200
192
201
193
/**
202
- * @param $productId
203
- * @return false|\Magento\Catalog\Api\Data\ProductInterface
194
+ * Get Product by ID
195
+ *
196
+ * @param mixed $productId
197
+ * @return false|ProductInterface
204
198
*/
205
- public function getProductById ($ productId ): bool | \ Magento \ Catalog \ Api \ Data \ ProductInterface
199
+ public function getProductById ($ productId )
206
200
{
207
201
try {
208
202
return $ this ->productRepository ->getById ($ productId );
@@ -214,7 +208,7 @@ public function getProductById($productId): bool|\Magento\Catalog\Api\Data\Produ
214
208
/**
215
209
* Return the categories for the given product
216
210
*
217
- * @param \Magento\Catalog\Model\ Product $product
211
+ * @param Product $product
218
212
* @return string
219
213
*/
220
214
public function getCategoriesForProduct ($ product ): string
@@ -248,7 +242,7 @@ public function getContentType(Product $product): string
248
242
}
249
243
250
244
/**
251
- * Get content id
245
+ * Get Content IDs (Product IDs)
252
246
*
253
247
* @param Product $product
254
248
* @return bool|int|string
@@ -261,10 +255,10 @@ public function getContentId(Product $product)
261
255
/**
262
256
* Return the price for the given product
263
257
*
264
- * @param \Magento\Catalog\Model\ Product $product
258
+ * @param Product $product
265
259
* @return float
266
260
*/
267
- public function getValueForProduct ($ product ): float
261
+ public function getValueForProduct (Product $ product ): float
268
262
{
269
263
$ price = $ product ->getFinalPrice ();
270
264
return $ this ->pricingHelper ->currency ($ price , false , false );
@@ -274,7 +268,8 @@ public function getValueForProduct($product): float
274
268
* Return the currency used in the store
275
269
*
276
270
* @return string
277
- * @throws \Magento\Framework\Exception\NoSuchEntityException
271
+ * @throws NoSuchEntityException
272
+ * @throws LocalizedException
278
273
*/
279
274
public function getCurrency (): string
280
275
{
@@ -389,7 +384,7 @@ public function getOrderContentIds(): array
389
384
*
390
385
* @return float|null
391
386
*/
392
- public function getOrderTotal ()
387
+ public function getOrderTotal (): ? float
393
388
{
394
389
$ order = $ this ->checkoutSession ->getLastRealOrder ();
395
390
if (!$ order ) {
@@ -405,7 +400,6 @@ public function getOrderTotal()
405
400
406
401
/**
407
402
* Return information about the last order items
408
- *
409
403
* @link https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data/#contents
410
404
*
411
405
* @return array
@@ -465,7 +459,7 @@ public function getCurrentCustomer(): ?Customer
465
459
/**
466
460
* Return the address of a given customer
467
461
*
468
- * @param object $customer
462
+ * @param mixed $customer
469
463
* @return Address
470
464
*/
471
465
public function getCustomerAddress ($ customer ): Address
@@ -474,42 +468,12 @@ public function getCustomerAddress($customer): Address
474
468
return $ this ->addressFactory ->create ()->load ($ customerAddressId );
475
469
}
476
470
477
- /**
478
- * Return the region's code for the given address
479
- *
480
- * @param object $address
481
- * @return string|null
482
- */
483
- public function getRegionCodeForAddress ($ address ): ?string
484
- {
485
- $ region = $ this ->regionFactory ->create ()->load ($ address ->getRegionId ());
486
- if ($ region ) {
487
- return $ region ->getCode ();
488
- } else {
489
- return null ;
490
- }
491
- }
492
-
493
- /**
494
- * Return the string representation of the customer gender
495
- *
496
- * @param object $customer
497
- * @return string|null
498
- */
499
- public function getGenderAsString ($ customer ): ?string
500
- {
501
- if ($ customer ->getGender ()) {
502
- return $ customer ->getResource ()->getAttribute ('gender ' )->getSource ()->getOptionText ($ customer ->getGender ());
503
- }
504
- return null ;
505
- }
506
-
507
471
/**
508
472
* Return all of the match keys that can be extracted from order information
509
473
*
510
474
* @return array
511
- * @throws \Magento\Framework\Exception\ LocalizedException
512
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
475
+ * @throws LocalizedException
476
+ * @throws NoSuchEntityException
513
477
*/
514
478
public function getUserDataFromOrder (): array
515
479
{
@@ -550,8 +514,8 @@ public function getUserDataFromOrder(): array
550
514
* Return all of the match keys that can be extracted from user session
551
515
*
552
516
* @return array
553
- * @throws \Magento\Framework\Exception\ LocalizedException
554
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
517
+ * @throws LocalizedException
518
+ * @throws NoSuchEntityException
555
519
*/
556
520
public function getUserDataFromSession (): array
557
521
{
@@ -589,9 +553,9 @@ public function getUserDataFromSession(): array
589
553
}
590
554
591
555
/**
592
- * Hash value
556
+ * Get Hash value
593
557
*
594
- * @param string $string
558
+ * @param $string
595
559
* @return string
596
560
*/
597
561
private function hashValue ($ string ): string
@@ -603,6 +567,8 @@ private function hashValue($string): string
603
567
* Get active quote
604
568
*
605
569
* @return Quote
570
+ * @throws LocalizedException
571
+ * @throws NoSuchEntityException
606
572
*/
607
573
public function getQuote (): Quote
608
574
{
0 commit comments