96 private $shipmentTypeColumn =
'bundle_shipment_type';
103 private $shipmentTypeMapping = [
111 private $optionCollections = [];
116 private $storeIdToCode = [];
121 private $optionCollectionCacheKey =
'_cache_instance_options_collection';
126 private $storeManager;
140 private function getBundleColumns()
142 return array_merge($this->bundleColumns, [$this->shipmentTypeColumn]);
158 )->addAttributeToFilter(
160 [
'eq' => \
Magento\Catalog\Model\Product\Type::TYPE_BUNDLE]
205 return $additionalRowsCount;
219 $this->bundleData[
$id][$this->shipmentTypeColumn] = $this->getShipmentTypeValue(
238 $optionCollections = $this->getProductOptionCollection(
$product);
240 $optionTitles = $this->getBundleOptionTitles(
$product);
241 foreach ($optionCollections->getItems() as
$option) {
251 return rtrim(
$bundleData, ImportProductModel::PSEUDO_MULTI_LINE_SEPARATOR);
264 $selections->addAttributeToSort(
'position');
265 foreach ($selections as $selection) {
267 'sku' => $selection->getSku(),
268 'price' => $selection->getSelectionPriceValue(),
269 'default' => $selection->getIsDefault(),
270 'default_qty' => $selection->getSelectionQty(),
272 'can_change_qty' => $selection->getSelectionCanChangeQty(),
275 . ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
277 ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
280 return $key . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR .
$value;
283 array_keys($selectionData)
286 . ImportProductModel::PSEUDO_MULTI_LINE_SEPARATOR;
301 array $optionTitles = []
303 $names = implode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, array_map(
307 $optionTitles[
$option->getOptionId()],
308 array_keys($optionTitles[
$option->getOptionId()])
310 return $names . ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
311 .
'type' . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR
312 .
$option->getType() . ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
313 .
'required' . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR
347 return $this->priceTypeMapping[
$type] ??
null;
356 private function getShipmentTypeValue(
$type)
358 return $this->shipmentTypeMapping[
$type] ??
null;
369 if (!empty($dataRow[
'additional_attributes'])) {
370 $additionalAttributes = $this->parseAdditionalAttributes($dataRow[
'additional_attributes']);
385 $filteredAttributes = [];
386 foreach ($additionalAttributes as
$code =>
$value) {
387 if (!in_array(
'bundle_' .
$code, $this->getBundleColumns())) {
388 $filteredAttributes[] =
$code . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR .
$value;
391 return implode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $filteredAttributes);
400 private function parseAdditionalAttributes($additionalAttributes)
402 $attributeNameValuePairs = explode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalAttributes);
403 $preparedAttributes = [];
407 if (strpos(
$attributeData, ImportProductModel::PAIR_NAME_VALUE_SEPARATOR) ===
false) {
411 $preparedAttributes[
$code] .= ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR .
$attributeData;
417 return $preparedAttributes;
434 private function getBundleOptionTitles(\
Magento\Catalog\Model\Product
$product): array
436 $optionCollections = $this->getProductOptionCollection(
$product);
439 foreach ($optionCollections->getItems() as
$option) {
442 $storeIds =
$product->getStoreIds();
443 if (count($storeIds) > 1) {
445 $optionCollections = $this->getProductOptionCollection(
$product, (
int)
$storeId);
447 foreach ($optionCollections->getItems() as
$option) {
448 $optionTitle =
$option->getTitle();
449 if ($optionsTitles[
$option->getId()][
'name'] != $optionTitle) {
450 $optionsTitles[
$option->getId()][
'name_' . $this->getStoreCodeById((
int)
$storeId)] =
456 return $optionsTitles;
468 private function getProductOptionCollection(
473 if (!isset($this->optionCollections[$productSku][
$storeId])) {
474 $product->unsetData($this->optionCollectionCacheKey);
476 $this->optionCollections[$productSku][
$storeId] =
$product->getTypeInstance()
480 return $this->optionCollections[$productSku][
$storeId];
491 private function getStoreCodeById(
int $storeId): string
493 if (!isset($this->storeIdToCode[
$storeId])) {
494 $this->storeIdToCode[
$storeId] = $this->storeManager->getStore(
$storeId)->getCode();
496 return $this->storeIdToCode[
$storeId];
getFormattedBundleOptionValues(\Magento\Catalog\Model\Product $product)
const SHIPMENT_SEPARATELY
const BUNDLE_WEIGHT_TYPE_COL
getFormattedOptionValues(\Magento\Bundle\Model\Option $option, array $optionTitles=[])
getFormattedBundleSelections($optionValues, SelectionCollection $selections)
const BUNDLE_PRICE_VIEW_COL
cleanNotBundleAdditionalAttributes($dataRow)
getNotBundleAttributes($additionalAttributes)
__construct(StoreManagerInterface $storeManager)
prepareData($collection, $productIds)
addHeaderColumns($columns)
getAdditionalRowsCount($additionalRowsCount, $productId)
const BUNDLE_PRICE_TYPE_COL
const BUNDLE_SKU_TYPE_COL
addData($dataRow, $productId)
populateBundleData($collection)