本文整理汇总了PHP中Magento\Catalog\Helper\Product::prepareProductOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::prepareProductOptions方法的具体用法?PHP Product::prepareProductOptions怎么用?PHP Product::prepareProductOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Helper\Product
的用法示例。
在下文中一共展示了Product::prepareProductOptions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderConfigureResult
/**
* Prepares and render result of composite product configuration request
*
* The $configureResult variable holds either:
* - 'ok' = true, and 'product_id', 'buy_request', 'current_store_id', 'current_customer_id'
* - 'error' = true, and 'message' to show
*
* @param \Magento\Framework\DataObject $configureResult
* @return \Magento\Framework\View\Result\Layout
*/
public function renderConfigureResult(\Magento\Framework\DataObject $configureResult)
{
try {
if (!$configureResult->getOk()) {
throw new \Magento\Framework\Exception\LocalizedException(__($configureResult->getMessage()));
}
$currentStoreId = (int) $configureResult->getCurrentStoreId();
if (!$currentStoreId) {
$currentStoreId = $this->_storeManager->getStore()->getId();
}
$product = $this->productRepository->getById($configureResult->getProductId(), false, $currentStoreId);
$this->_coreRegistry->register('current_product', $product);
$this->_coreRegistry->register('product', $product);
// Register customer we're working with
$customerId = (int) $configureResult->getCurrentCustomerId();
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
// Prepare buy request values
$buyRequest = $configureResult->getBuyRequest();
if ($buyRequest) {
$this->_catalogProduct->prepareProductOptions($product, $buyRequest);
}
$isOk = true;
$productType = $product->getTypeId();
} catch (\Exception $e) {
$isOk = false;
$productType = null;
$this->_coreRegistry->register('composite_configure_result_error_message', $e->getMessage());
}
return $this->_initConfigureResultLayout($isOk, $productType);
}
示例2: testPrepareProductOptions
public function testPrepareProductOptions()
{
/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
$buyRequest = new \Magento\Framework\DataObject(['qty' => 100, 'options' => ['option' => 'value']]);
$this->_helper->prepareProductOptions($product, $buyRequest);
$result = $product->getPreconfiguredValues();
$this->assertInstanceOf('Magento\\Framework\\DataObject', $result);
$this->assertEquals(100, $result->getQty());
$this->assertEquals(['option' => 'value'], $result->getOptions());
}
示例3: renderConfigureResult
/**
* Prepares and render result of composite product configuration request
*
* The $configureResult variable holds either:
* - 'ok' = true, and 'product_id', 'buy_request', 'current_store_id', 'current_customer_id'
* - 'error' = true, and 'message' to show
*
* @param \Magento\Framework\Object $configureResult
* @return void
*/
public function renderConfigureResult(\Magento\Framework\Object $configureResult)
{
try {
if (!$configureResult->getOk()) {
throw new \Magento\Framework\Model\Exception($configureResult->getMessage());
}
$currentStoreId = (int) $configureResult->getCurrentStoreId();
if (!$currentStoreId) {
$currentStoreId = $this->_storeManager->getStore()->getId();
}
$product = $this->_productFactory->create()->setStoreId($currentStoreId)->load($configureResult->getProductId());
if (!$product->getId()) {
throw new \Magento\Framework\Model\Exception(__('The product is not loaded.'));
}
$this->_coreRegistry->register('current_product', $product);
$this->_coreRegistry->register('product', $product);
// Register customer we're working with
$customerId = (int) $configureResult->getCurrentCustomerId();
// TODO: Remove the customer model from the registry once all readers are refactored
$customerModel = $this->_converter->loadCustomerModel($customerId);
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER, $customerModel);
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
// Prepare buy request values
$buyRequest = $configureResult->getBuyRequest();
if ($buyRequest) {
$this->_catalogProduct->prepareProductOptions($product, $buyRequest);
}
$isOk = true;
$productType = $product->getTypeId();
} catch (\Exception $e) {
$isOk = false;
$productType = null;
$this->_coreRegistry->register('composite_configure_result_error_message', $e->getMessage());
}
$this->_initConfigureResultLayout($isOk, $productType);
$this->_view->renderLayout();
}