Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodriigomedeiros/7f56d555716615fdc290c8f0576006da to your computer and use it in GitHub Desktop.
Save rodriigomedeiros/7f56d555716615fdc290c8f0576006da to your computer and use it in GitHub Desktop.
As propriedades do produto (WC_Abstract_Legacy_Product) não podem ser acessadas diretamente. A correção visa elimitar warnings no error_log, quando apache e versão do WooCommerce >= 3.0
<?php
class WC_Intelipost_Quote_Product
{
private $_packages = array ();
protected $_simpleProducts = array ();
private $_dimensions;
protected $_productsQty = array();
public function fetchProductQuote($items, $dimensions)
{
$this->_dimensions = $dimensions;
$j = 0;
foreach ($items as $item_id => $values)
{
/** @var WC_Product $product */
$product = $values['data'];
$qty = $values['quantity'];
$productWidth = $product->get_width() ? $product->get_width() : $this->_dimensions->_widthAttribute;
$productHeight = $product->get_weight() ? $product->get_weight(): $this->_dimensions->_heightAttribute;
$productLength = $product->get_length() ? $product->get_length() : $this->_dimensions->_lengthAttribute;
$productPrice = $product->get_price();
$productWeight = $this->_dimensions->_getCustomWeight($product->get_weight());
$productVolume = null;
//$productVolume = $this->_getVolume ($product);
$productSku = $product->get_sku();
$productTitle = $product->get_title();
//$cubic = $this->_getCubic ($productVolume);
$data = array( 'packageData' => array(
'width' => $productWidth,
'height' => $productHeight,
'length' => $productLength,
'price' => str_replace(',', '.', $productPrice),
'weight' => $productWeight,
'volume' => $productVolume,
'sku' => $productSku,
'title' => $productTitle,
'qty' => $qty,
));
$this->_addToPackage ($data['packageData'], $j ++);
}
}
private function _addToPackage ($packageData, $index)
{
$this->_packages[$index] = $packageData;
}
public function getPackages()
{
return $this->_packages;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment