示例#1
0
 private function getOptionMatcher()
 {
     if (!is_null($this->optionMatcher)) {
         return $this->optionMatcher;
     }
     $this->optionMatcher = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Option');
     $this->optionMatcher->setMagentoProduct($this->getProcessor()->getListingProduct()->getMagentoProduct());
     $this->optionMatcher->setMatchedAttributes($this->getProcessor()->getTypeModel()->getMatchedAttributes());
     return $this->optionMatcher;
 }
    public function callbackColumnTitle($value, $row, $column, $isExport)
    {
        $value = '<div style="margin-left: 3px; margin-bottom: 3px;">' . Mage::helper('M2ePro')->escapeHtml($value) . "</div>";
        $id = $row->getId();
        $generalId = $row->getData('general_id');
        $categoryLinkTitle = Mage::helper('M2ePro')->escapeHtml('Show Categories');
        $notFoundText = Mage::helper('M2ePro')->__('Categories Not Found');
        $value .= <<<HTML
<div style="margin-left: 3px; margin-bottom: 10px; font-size:10px; line-height: 1.1em">
    <a href="javascript:void(0)"
        onclick="ListingGridHandlerObj.productSearchHandler.showAsinCategories(
            this, {$id}, '{$generalId}', {$this->productId})">
        {$categoryLinkTitle}
    </a>
    <div id="asin_categories_{$id}"></div>
    <div id="asin_categories_not_found_{$id}" style="display: none; font-style: italic">{$notFoundText}</div>
</div>
HTML;
        if (!$this->listingProduct->getChildObject()->getVariationManager()->isVariationProduct() || $this->listingProduct->getChildObject()->getVariationManager()->isIndividualType()) {
            if (!$row->getData('is_variation_product')) {
                return $value;
            }
        } else {
            if (!$row->getData('is_variation_product')) {
                return $value;
            }
        }
        if ($row->getData('is_variation_product') && $row->getData('bad_parent')) {
            return $value;
        }
        $variations = $row->getData('variations');
        if ($this->listingProduct->getChildObject()->getVariationManager()->isRelationParentType()) {
            $magentoProductAttributesHtml = '';
            $magentoProductAttributesJs = '';
            $destinationAttributes = array_keys($variations['set']);
            $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
            $this->matcherAttributes->setDestinationAttributes($destinationAttributes);
            if ($this->matcherAttributes->isAmountEqual()) {
                $magentoProductAttributesJs .= '<script type="text/javascript">';
                $magentoProductAttributesHtml .= '<div><span style="margin-left: 10px;
                                        font-size: 11px;
                                        font-weight: bold;
                                        color: #808080;
                                        display: inline-block;
                                        width: 170px;">' . Mage::helper('M2ePro')->__('Magento Attributes') . '</span><span style="margin-left: 10px;
                                        font-size: 11px;
                                        font-weight: bold;
                                        color: #808080;
                                        display: inline-block;">' . Mage::helper('M2ePro')->__('Amazon Attributes') . '</span></div>';
                $matchedAttributes = $this->matcherAttributes->getMatchedAttributes();
                $attributeId = 0;
                foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
                    $magentoProductAttributesHtml .= '<span style="margin-left: 10px;
                                            font-size: 11px;
                                            color: #808080;
                                            display: inline-block;
                                            width: 170px;">' . ucfirst(strtolower($magentoAttr)) . '</span>';
                    $magentoProductAttributesHtml .= '<input type="hidden" value="' . Mage::helper('M2ePro')->escapeHtml($magentoAttr) . '"
                                       id="magento_product_attribute_' . $attributeId . '_' . $id . '">';
                    $magentoProductAttributesHtml .= '<select class="amazon_product_attribute_' . $id . '"
                                       onchange="ListingGridHandlerObj.productSearchHandler.attributesChange(this)"
                                       style="width: 170px; margin-left: 10px;
                                              margin-bottom: 7px; font-size: 10px;"
                                       id="amazon_product_attribute_' . $attributeId . '_' . $id . '">';
                    if (!array_key_exists($amazonAttr, $variations['set'])) {
                        $magentoProductAttributesHtml .= '<option class="empty" value=""></option>';
                    }
                    foreach ($variations['set'] as $attrKey => $attrData) {
                        $selected = '';
                        if ($attrKey == $amazonAttr) {
                            $selected = 'selected';
                            $magentoProductAttributesJs .= <<<JS
ListingGridHandlerObj.productSearchHandler.attributesChange({id:"magento_product_attribute_{$magentoAttr}_{$id}"});
JS;
                        }
                        $attrKey = Mage::helper('M2ePro')->escapeHtml($attrKey);
                        $magentoProductAttributesHtml .= '<option value="' . $attrKey . '" ' . $selected . '>' . $attrKey . '</option>';
                    }
                    $magentoProductAttributesHtml .= '</select><br/>';
                    $attributeId++;
                }
                $magentoProductAttributesJs .= '</script>';
                $magentoProductAttributesHtml .= '<div id="variations_' . $id . '" style="display: none;">' . json_encode($variations) . '</div>';
            } else {
                $matchedAttributes = json_encode($this->matcherAttributes->getMatchedAttributes());
                $destinationAttributes = json_encode($destinationAttributes);
                foreach ($variations['set'] as $attribute => $options) {
                    $variations['set'][$attribute] = array_values($options);
                }
                $amazonVariations = json_encode($variations);
                $magentoAttributesText = Mage::helper('M2ePro')->__('Magento Attributes');
                $amazonAttributesText = Mage::helper('M2ePro')->__('Amazon Attributes');
                $searchHandler = 'ListingGridHandlerObj.productSearchHandler';
                $value .= <<<HTML
<form id="matching_attributes_form_{$id}" action="javascript:void(0)">
        <div class="matching-attributes-table" style="display:table;padding-left:10px;font-size: 11px;color: #808080;">
            <div class="matching-attributes-table-header"
                style="display: table-row; font-weight: bold;">
                <div style="display:table-cell; width: 170px; padding-right: 10px;">
                    <span>{$magentoAttributesText}</span>
                </div>
                <div style="display:table-cell;">
                    <span>{$amazonAttributesText}</span>
                </div>
            </div>
        </div>
    </form>
</div>
HTML;
                if ($this->matcherAttributes->isSourceAmountGreater()) {
                    $magentoProductVariationsSet = $this->listingProduct->getMagentoProduct()->getVariationInstance()->getVariationsTypeStandard();
                    $magentoProductVariationsSet = json_encode($magentoProductVariationsSet['set']);
                    $productAttributes = json_encode($this->listingProduct->getChildObject()->getVariationManager()->getTypeModel()->getProductAttributes());
                    $value .= <<<HTML
<script type="application/javascript">
    {$searchHandler}.searchData[{$id}] = {};
    {$searchHandler}.searchData[{$id}].matchingType = {$searchHandler}.MATCHING_TYPE_VIRTUAL_AMAZON;
    {$searchHandler}.searchData[{$id}].matchedAttributes = {$matchedAttributes};
    {$searchHandler}.searchData[{$id}].productAttributes = {$productAttributes};
    {$searchHandler}.searchData[{$id}].destinationAttributes = {$destinationAttributes};
    {$searchHandler}.searchData[{$id}].magentoVariationSet = {$magentoProductVariationsSet};
    {$searchHandler}.searchData[{$id}].amazonVariation = {$amazonVariations};

    ListingGridHandlerObj.productSearchHandler.renderMatchedAttributesVirtualView({$id});
</script>
HTML;
                } else {
                    $value .= <<<HTML
<script type="application/javascript">
    {$searchHandler}.searchData[{$id}] = {};
    {$searchHandler}.searchData[{$id}].matchingType = {$searchHandler}.MATCHING_TYPE_VIRTUAL_MAGENTO;
    {$searchHandler}.searchData[{$id}].matchedAttributes = {$matchedAttributes};
    {$searchHandler}.searchData[{$id}].destinationAttributes = {$destinationAttributes};
    {$searchHandler}.searchData[{$id}].amazonVariation = {$amazonVariations};

    ListingGridHandlerObj.productSearchHandler.renderMatchedAttributesVirtualView({$id});
</script>
HTML;
                }
            }
            return $value . $magentoProductAttributesHtml . $magentoProductAttributesJs;
        }
        $specificsHtml = '';
        $specificsJs = '<script type="text/javascript">';
        // match options for individual
        if ($this->listingProduct->getChildObject()->getVariationManager()->isIndividualType() && $this->listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()) {
            $channelVariations = array();
            foreach ($variations['asins'] as $asin => $asinAttributes) {
                $channelVariations[$asin] = $asinAttributes['specifics'];
            }
            $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
            $this->matcherAttributes->setDestinationAttributes(array_keys($variations['set']));
            if ($this->matcherAttributes->isAmountEqual() && $this->matcherAttributes->isFullyMatched()) {
                $matchedAttributes = $this->matcherAttributes->getMatchedAttributes();
                $this->matcherOptions->setMagentoProduct($this->listingProduct->getMagentoProduct());
                $this->matcherOptions->setDestinationOptions($channelVariations);
                $this->matcherOptions->setMatchedAttributes($matchedAttributes);
                $productOptions = $this->listingProduct->getChildObject()->getVariationManager()->getTypeModel()->getProductOptions();
                $requestedChildAsin = $this->matcherOptions->getMatchedOptionGeneralId($productOptions);
            }
        }
        if (empty($requestedChildAsin)) {
            $requestedChildAsin = $row->getData('requested_child_id');
        }
        $selectedOptions = array();
        if ($requestedChildAsin) {
            $selectedOptions = $variations['asins'][$requestedChildAsin]['specifics'];
        }
        $specificsHtml .= '<form action="javascript:void(0);">';
        $attributesNames = '<span style="margin-left: 10px;
                                min-width: 100px;
                                max-width: 170px;
                                font-size: 11px;
                                color: #808080;
                                display: inline-block;">';
        $attributeValues = '<span style="margin-left: 5px; display: inline-block;">';
        foreach ($variations['set'] as $specificName => $specific) {
            $attributesNames .= '<span style="margin-bottom: 5px; display: inline-block;">' . ucfirst(strtolower($specificName)) . '</span><br/>';
            $attributeValues .= '<input type="hidden" value="' . Mage::helper('M2ePro')->escapeHtml($specificName) . '" class="specifics_name_' . $id . '">';
            $attributeValues .= '<select class="specifics_' . $id . '"
                                       onchange="ListingGridHandlerObj.productSearchHandler.specificsChange(this)"
                                       style="width: 170px; margin-bottom: 5px; font-size: 10px;"
                                       id="specific_' . $specificName . '_' . $id . '">';
            $attributeValues .= '<option class="empty" value=""></option>';
            if (!empty($requestedChildAsin)) {
                foreach ($specific as $option) {
                    $selected = '';
                    if ($selectedOptions[$specificName] == $option) {
                        $selected = 'selected';
                    }
                    $option = Mage::helper('M2ePro')->escapeHtml($option);
                    $attributeValues .= '<option value="' . $option . '" ' . $selected . '>' . $option . '</option>';
                }
            }
            $attributeValues .= '</select><br/>';
            $specificsJs .= <<<JS
ListingGridHandlerObj.productSearchHandler.specificsChange({id:"specific_{$specificName}_{$id}"});
JS;
        }
        $specificsHtml .= $attributesNames . '</span>';
        $specificsHtml .= $attributeValues . '</span>';
        $specificsHtml .= '</form>';
        $specificsJs .= '</script>';
        $variationAsins = json_encode($variations['asins']);
        $variationTree = json_encode($this->getChannelVariationsTree($variations));
        $specificsJsonContainer = <<<HTML
<div id="parent_asin_{$id}" style="display: none">{$generalId}</div>
<div id="asins_{$id}" style="display: none;">{$variationAsins}</div>
<div id="channel_variations_tree_{$id}" style="display: none;">{$variationTree}</div>
HTML;
        return $value . $specificsHtml . $specificsJsonContainer . $specificsJs;
    }