How to fix : extract() expects parameter 1 to be array?


I’m trying to fix an error extract() expects parameter 1 to be array with the following code:

The line is 33 with <—HERE

<?php if ($this->getFacebookPixelID()): ?>
    $order = Mage::getSingleton('sales/order');
    $totalData = $order->getData();
    $allitems  = $order->getAllVisibleItems();
    $ShippingAmount = $order->getShippingAmount();
    $itemsCollection = $order->getItemsCollection();
    $total_ordered_items = $order->getData('total_qty_ordered');
    $num_of_ordered_items = 0;
    $supplier_shipping_cost = 0;
    $totalprofit = 0;
$uniqueSupplierCodes = [];
foreach ($itemsCollection as $item){
   //$num_of_ordered_all_items += $item->getQtyOrdered(); // Number of all item ordered
   //$num_of_shipped_items += $item->getQtyShipped();  
   $product = Mage::getModel('catalog/product')->load($item->getProductId());
   $supplier_shipping_cost = $product->getData('supplier_shipping_cost');
   $supplier_code = $product->getAttributeText('supplier_code');
   $cost = $product->getData('cost');
   $price = $product->getFinalPrice();
   $num_of_ordered_items = number_format((float)$item->getQtyOrdered());
   $total_cost = $cost * $num_of_ordered_items; 
   $total_price = $price * $num_of_ordered_items;
   $subtotal_profit = $total_price - $total_cost;
   $profit_foreach_group = $subtotal_profit - $supplier_shipping_cost;
   $totalprofit += $profit_foreach_group;
    if(!in_array($supplier_code,$uniqueSupplierCodes)) {
      //$uniqueSupplierCodes[] = $supplier_code;
	  $a = extract($supplier_shipping_cost); <---HERE
	  echo $a;


/* foreach($order->getAllItems() as $item): 
      if($item->getParentItemId()) continue; 
          $product = Mage::getModel('catalog/product')->load($item->getProductId());
		  $totalProfit += ((float) $product->getData('profit')) * $item->getQtyOrdered();
endforeach; */
  fbq('track', 'Purchase', {
    source: 'magento',
    version: "<?php echo $this->getMagentoVersion() ?>",
    pluginVersion: "<?php echo $this->getPluginVersion() ?>",
    content_type: "<?php echo $this->getContentType() ?>",
    content_ids: [<?php echo $this->getContentIDs() ?>]
    <?php if ($this->getValue() && $this->getCurrency()) { ?>
      , value: <?php echo $totalprofit; ?>
    <?php } ?>
    <?php if ($this->getValue() && $this->getCurrency()) { ?>
      , currency: "<?php echo $this->getCurrency() ?>"
    <?php } ?>
<?php endif; ?>

Any help would be much appreciated.

Thank you

The error message is reasonably self-explanatory - extract() expects an associative array containing variable name/value pairs, which it then extracts into those variables. The documentation also shows that the function has no return - hence assigning the return to $a and trying to echo it won’t give you anything.

Exactly what are you trying to do here? Is extract() the correct function for it? That is, would your database table contain a variable name and a value in the product?

I’m trying to get my profit : )

Very difficult for me as I’m not good at these things but at least closer than just revenue.

I can’t picture why you would store both variable name and value in your database table in a way that the extract() function would help you to do that.

What do you pass in (i.e. what is in $supplier_shipping_cost) and what do you want to get out, into $a?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.