Skip to content

Commit 2d9f2d6

Browse files
bsuravechdamcou
authored andcommitted
update productDataArray for b2b to address countable error and refactoring of class (#915)
1 parent 58cceba commit 2d9f2d6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Helper/ProductDataArray.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66

77
class ProductDataArray extends DataObject
88
{
9+
/**
10+
* @return array
11+
*/
912
public function getItems()
1013
{
11-
return $this->getData('items');
14+
return $this->getData('items') ?: [];
1215
}
1316

14-
public function setItems(array $items)
17+
/**
18+
* @param array $items
19+
*/
20+
public function setItems($items = [])
1521
{
1622
$this->setData('items', $items);
1723
}
@@ -23,7 +29,7 @@ public function setItems(array $items)
2329
public function addProductData($productId, array $keyValuePairs)
2430
{
2531
$items = $this->getItems();
26-
if (count($items) && isset($items[$productId])) {
32+
if (is_array($items) && isset($items[$productId])) {
2733
$keyValuePairs = array_merge($items[$productId], $keyValuePairs);
2834
}
2935
$items[$productId] = $keyValuePairs;
@@ -32,8 +38,6 @@ public function addProductData($productId, array $keyValuePairs)
3238

3339
public function getItem($productId)
3440
{
35-
$items = $this->getItems();
36-
37-
return isset($items[$productId]) ? $items[$productId] : null;
41+
return $this->getData('items', $productId);
3842
}
3943
}

0 commit comments

Comments
 (0)