Skip to content

Commit

Permalink
Fixes issue that can prevent product import/export from completing
Browse files Browse the repository at this point in the history
Caused by ambiguous parameter type/check triggering warning on PHP >= 7.2 `count(): Parameter must be an array or an object that implements Countable`
  • Loading branch information
damanic committed Oct 25, 2023
1 parent 9a6747a commit 8a03713
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions classes/shop_optionmatrixmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ public function __construct()
* @param array $options A list of the record options in the following format: ['Color'=>'Red', 'Size'=>'M']
* @return mixed Returns an object containing the record data or NULL if the record cannot be found.
*/
public function get_record($product, $options)
public function get_record($product, $options=array())
{
if (is_object($product))
$product = $product->id;
$product_id = is_object($product) ? $product->id : $product;

if (!count($product))
if (!$product_id)
throw new Phpr_ApplicationException('Please specify product or product identifier.');

if (!count($options))
Expand All @@ -59,7 +58,7 @@ public function get_record($product, $options)

$hash = Shop_OptionMatrixRecord::generate_options_hash($options, false);

$result = Db_DbHelper::object('select * from shop_option_matrix_records where product_id=:product_id and options_hash=:hash', array('product_id'=>$product, 'hash'=>$hash));
$result = Db_DbHelper::object('select * from shop_option_matrix_records where product_id=:product_id and options_hash=:hash', array('product_id'=>$product_id, 'hash'=>$hash));
if (!$result)
return null;

Expand Down Expand Up @@ -125,7 +124,7 @@ public function get_record($product, $options)
* $status = $manager->add_or_update($test_product, $options, $data);
* </pre>
* @documentable
* @param Shop_Product $product Specifies a product the record belongs to.
* @param mixed $product Specifies either product identifier or product object ({@link Shop_Product}) the record belongs to.
* @param array $options A list of the product options and option values in the following format: ['Color'=>'Red', 'Size'=>'M'].
* @param array $data Data values to assign to the record.
* @param boolean $skip_existing Skip the operation if a record with specified options already exists (do not update it).
Expand All @@ -145,11 +144,9 @@ public function add_or_update($product, $options, $data, $skip_existing = false)
/*
* Find existing record
*/

$existing_record = $this->get_record($product, $options);
if (is_object($product))
$product = $product->id;

$product_id = is_object($product) ? $product->id : $product;

$existing_record = $this->get_record($product_id, $options);
if ($existing_record && $skip_existing)
{
$result->status = self::status_skipped;
Expand All @@ -161,7 +158,7 @@ public function add_or_update($product, $options, $data, $skip_existing = false)
* Load product options
*/

$product_options = $this->load_product_option_ids($product);
$product_options = $this->load_product_option_ids($product_id);

/*
* Check whether all options exist in the product
Expand Down

0 comments on commit 8a03713

Please sign in to comment.