在 PHP 中,我如何使用其中一个参数是 class 的函数:
In PHP how do i use a function where one of the parameters is a class:
在 magento 2.2.1 中,有一个我正在尝试使用的函数,它有一个 class 作为参数:
public function add($sku, \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice);
这过去只有 4 个传递给它的参数,使用方式如下:
$this->tierInterface->add($sku,$groupId,$price, '1');
然而,现在需要使用第二个参数来代替这些旧参数,其中 \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice
包含以下我需要使用的方法:
public function setQty($qty);
public function setValue($value);
public function setCustomerGroupId($customerGroupId);
如何使用这些新方法将值正确传递给函数?
在 Magento 2 中有一个 concrete implementation of ProductTierPriceInterface
你应该使用它被命名为 TierPrice
.
您的新代码如下所示:
# Pretty sure dependency injection should be needed there.
$tierPrice = new TierPrice();
$tierPrice->setQty(1);
$tierPrice->setValue($price);
$tierPrice->setCustomerGroupId($groupId);
$this->tierInterface->add($sku, $tierPrice);
在 magento 2.2.1 中,有一个我正在尝试使用的函数,它有一个 class 作为参数:
public function add($sku, \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice);
这过去只有 4 个传递给它的参数,使用方式如下:
$this->tierInterface->add($sku,$groupId,$price, '1');
然而,现在需要使用第二个参数来代替这些旧参数,其中 \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice
包含以下我需要使用的方法:
public function setQty($qty);
public function setValue($value);
public function setCustomerGroupId($customerGroupId);
如何使用这些新方法将值正确传递给函数?
在 Magento 2 中有一个 concrete implementation of ProductTierPriceInterface
你应该使用它被命名为 TierPrice
.
您的新代码如下所示:
# Pretty sure dependency injection should be needed there.
$tierPrice = new TierPrice();
$tierPrice->setQty(1);
$tierPrice->setValue($price);
$tierPrice->setCustomerGroupId($groupId);
$this->tierInterface->add($sku, $tierPrice);