本文整理汇总了PHP中Magento\Sales\Model\Order\Creditmemo::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Creditmemo::setData方法的具体用法?PHP Creditmemo::setData怎么用?PHP Creditmemo::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\Order\Creditmemo
的用法示例。
在下文中一共展示了Creditmemo::setData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCollect
/**
* @param array $creditmemoData
* @param array $expectedResults
* @dataProvider collectDataProvider
*/
public function testCollect($creditmemoData, $expectedResults)
{
$roundingDelta = [];
//Set up weeeData mock
$this->weeeData->expects($this->once())->method('includeInSubtotal')->will($this->returnValue($creditmemoData['include_in_subtotal']));
//Set up invoice mock
/** @var \Magento\Sales\Model\Order\Invoice\Item[] $creditmemoItems */
$creditmemoItems = [];
foreach ($creditmemoData['items'] as $itemKey => $creditmemoItemData) {
$creditmemoItems[$itemKey] = $this->getInvoiceItem($creditmemoItemData);
}
$this->creditmemo->expects($this->once())->method('getAllItems')->will($this->returnValue($creditmemoItems));
foreach ($creditmemoData['data_fields'] as $key => $value) {
$this->creditmemo->setData($key, $value);
}
$this->creditmemo->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
if (!isset($roundingDelta[$type])) {
$roundingDelta[$type] = 0;
}
$roundedPrice = round($price + $roundingDelta[$type], 2);
$roundingDelta[$type] = $price - $roundedPrice;
return $roundedPrice;
}));
$this->model->collect($this->creditmemo);
//verify invoice data
foreach ($expectedResults['creditmemo_data'] as $key => $value) {
$this->assertEquals($value, $this->creditmemo->getData($key), 'Creditmemo data field ' . $key . ' is incorrect');
}
//verify invoice item data
foreach ($expectedResults['creditmemo_items'] as $itemKey => $itemData) {
$creditmemoItem = $creditmemoItems[$itemKey];
foreach ($itemData as $key => $value) {
if ($key == 'tax_ratio') {
$taxRatio = unserialize($creditmemoItem->getData($key));
$expectedTaxRatio = unserialize($itemData[$key]);
$this->assertEquals($expectedTaxRatio['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
} else {
$this->assertEquals($value, $creditmemoItem->getData($key), 'Creditmemo item field ' . $key . ' is incorrect');
}
}
}
}
示例2: testCollect
/**
* @param array $orderData
* @param array $creditmemoData
* @param array $expectedResults
* @dataProvider collectDataProvider
*/
public function testCollect($orderData, $creditmemoData, $expectedResults)
{
$roundingDelta = [];
//Set up order mock
foreach ($orderData['data_fields'] as $key => $value) {
$this->order->setData($key, $value);
}
//Set up creditmemo mock
/** @var \Magento\Sales\Model\Order\Creditmemo\Item[] $creditmemoItems */
$creditmemoItems = [];
foreach ($creditmemoData['items'] as $itemKey => $creditmemoItemData) {
$creditmemoItems[$itemKey] = $this->getCreditmemoItem($creditmemoItemData);
}
$this->creditmemo->expects($this->once())->method('getAllItems')->will($this->returnValue($creditmemoItems));
$this->creditmemo->expects($this->any())->method('isLast')->will($this->returnValue($creditmemoData['is_last']));
foreach ($creditmemoData['data_fields'] as $key => $value) {
$this->creditmemo->setData($key, $value);
}
$this->creditmemo->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
if (!isset($roundingDelta[$type])) {
$roundingDelta[$type] = 0;
}
$roundedPrice = round($price + $roundingDelta[$type], 2);
$roundingDelta[$type] = $price - $roundedPrice;
return $roundedPrice;
}));
$this->model->collect($this->creditmemo);
//verify invoice data
foreach ($expectedResults['creditmemo_data'] as $key => $value) {
$this->assertEquals($value, $this->creditmemo->getData($key));
}
//verify invoice item data
foreach ($expectedResults['creditmemo_items'] as $itemKey => $itemData) {
$creditmemoItem = $creditmemoItems[$itemKey];
foreach ($itemData as $key => $value) {
$this->assertEquals($value, $creditmemoItem->getData($key));
}
}
}