コード例 #1
0
ファイル: Curl.php プロジェクト: QiuLihua83/magento-ee
 /**
  * Parse bundle selections in response.
  *
  * @param string $id
  * @return array
  */
 protected function parseResponseSelections($id)
 {
     $url = $_ENV['app_backend_url'] . "bundle_product_edit/form/id/{$id}/back/edit/tab/product_info_tabs_group_7/";
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->write(CurlInterface::POST, $url, '1.1');
     $response = $curl->read();
     $curl->close();
     $selectionIdKey = 1;
     $optionIdKey = 2;
     $productNameKey = 3;
     $responseSelections = [];
     $bundleSelections = $this->fixture->getBundleSelections();
     preg_match_all('/{.*"selection_id":"(\\d+)".*"option_id":"(\\d+)".*"name":"([^"]+)".*}/', $response, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $productName = $match[$productNameKey];
         $responseSelections[$productName] = ['selection_id' => $match[$selectionIdKey], 'option_id' => $match[$optionIdKey]];
     }
     foreach ($bundleSelections as $optionKey => $option) {
         foreach ($option['assigned_products'] as $assignedKey => $optionValue) {
             $productName = $optionValue['name'];
             $bundleSelections[$optionKey]['assigned_products'][$assignedKey] += $responseSelections[$productName];
         }
     }
     return ['bundle_selections' => $bundleSelections];
 }
コード例 #2
0
 /**
  * Prepare bundle options.
  *
  * @return array|null
  */
 protected function prepareBundleOptions()
 {
     $result = [];
     $bundleSelections = $this->product->getBundleSelections();
     $assignedProducts = $this->product->getDataFieldConfig('bundle_selections')['source']->getProducts();
     foreach ($bundleSelections as $optionKey => $bundleOption) {
         $options = $this->getOptions($bundleOption['assigned_products'], $assignedProducts[$optionKey], $bundleOption['type']);
         $optionData = ['title' => $bundleOption['title'], 'type' => $bundleOption['type'], 'is_require' => $bundleOption['required'], 'options' => $options];
         $result[$optionKey] = $this->sortDataByPath($optionData, 'options::title');
     }
     return $this->sortDataByPath($result, '::title');
 }
コード例 #3
0
ファイル: Curl.php プロジェクト: hientruong90/ee_14_installer
 /**
  * Prepare data for bundle product.
  *
  * @param BundleProduct $product
  * @return array
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function prepareBundleData(BundleProduct $product)
 {
     $result = [];
     $checkoutData = $product->getCheckoutData();
     $bundleOptions = isset($checkoutData['options']['bundle_options']) ? $checkoutData['options']['bundle_options'] : [];
     $bundleSelections = $product->getBundleSelections();
     $bundleSelectionsData = [];
     $result['qty'] = $checkoutData['qty'];
     foreach ($bundleSelections as $option) {
         foreach ($option['assigned_products'] as $productData) {
             $bundleSelectionsData[] = ['selection_id' => $productData['selection_id'], 'option_id' => $productData['option_id']];
         }
     }
     foreach ($bundleOptions as $option) {
         $key = substr($option['value']['name'], -1);
         if (isset($bundleSelectionsData[$key])) {
             $optionId = $bundleSelectionsData[$key]['option_id'];
             $selectionId = $bundleSelectionsData[$key]['selection_id'];
             $result['bundle_option'][$optionId] = $selectionId;
         }
     }
     return $result;
 }
コード例 #4
0
ファイル: View.php プロジェクト: hientruong90/ee_14_installer
 /**
  * Prepare checkout data for fill bundle options.
  *
  * @param BundleProduct $product
  * @return array
  */
 protected function prepareBundleCheckoutData(BundleProduct $product)
 {
     $assignedProducts = $product->getDataFieldConfig('bundle_selections')['source']->getProducts();
     $bundleOptions = $product->getBundleSelections();
     $checkoutData = $product->getCheckoutData();
     $checkoutData = isset($checkoutData['options']['bundle_options']) ? $checkoutData['options']['bundle_options'] : [];
     foreach ($checkoutData as $optionKey => $option) {
         $optionIndex = str_replace('option_key_', '', $optionKey);
         $names = explode(',', $checkoutData[$optionKey]['value']['name']);
         $checkoutData[$optionKey]['title'] = $bundleOptions[$optionIndex]['title'];
         $checkoutData[$optionKey]['type'] = $bundleOptions[$optionIndex]['type'];
         $checkoutData[$optionKey]['value']['name'] = $this->prepareOptionValue($names, $assignedProducts[$optionIndex]);
     }
     return $checkoutData;
 }