本文整理汇总了PHP中Magento\Catalog\Model\Product\Option::getValueInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::getValueInstance方法的具体用法?PHP Option::getValueInstance怎么用?PHP Option::getValueInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product\Option
的用法示例。
在下文中一共展示了Option::getValueInstance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: duplicate
/**
* Duplicate custom options for product
*
* @param \Magento\Catalog\Model\Product\Option $object
* @param int $oldProductId
* @param int $newProductId
* @return \Magento\Catalog\Model\Product\Option
*/
public function duplicate(\Magento\Catalog\Model\Product\Option $object, $oldProductId, $newProductId)
{
$connection = $this->getConnection();
$optionsCond = [];
$optionsData = [];
// read and prepare original product options
$select = $connection->select()->from($this->getTable('catalog_product_option'))->where('product_id = ?', $oldProductId);
$query = $connection->query($select);
while ($row = $query->fetch()) {
$optionsData[$row['option_id']] = $row;
$optionsData[$row['option_id']]['product_id'] = $newProductId;
unset($optionsData[$row['option_id']]['option_id']);
}
// insert options to duplicated product
foreach ($optionsData as $oId => $data) {
$connection->insert($this->getMainTable(), $data);
$optionsCond[$oId] = $connection->lastInsertId($this->getMainTable());
}
// copy options prefs
foreach ($optionsCond as $oldOptionId => $newOptionId) {
// title
$table = $this->getTable('catalog_product_option_title');
$select = $this->getConnection()->select()->from($table, [new \Zend_Db_Expr($newOptionId), 'store_id', 'title'])->where('option_id = ?', $oldOptionId);
$insertSelect = $connection->insertFromSelect($select, $table, ['option_id', 'store_id', 'title'], \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE);
$connection->query($insertSelect);
// price
$table = $this->getTable('catalog_product_option_price');
$select = $connection->select()->from($table, [new \Zend_Db_Expr($newOptionId), 'store_id', 'price', 'price_type'])->where('option_id = ?', $oldOptionId);
$insertSelect = $connection->insertFromSelect($select, $table, ['option_id', 'store_id', 'price', 'price_type'], \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE);
$connection->query($insertSelect);
$object->getValueInstance()->duplicate($oldOptionId, $newOptionId);
}
return $object;
}