Magento 1.9 предварительный выбор настраиваемых параметров (образцов)


Есть ли способ, чтобы Magento 1.9 автоматически выбирал один из своих простых продуктов из настраиваемого продукта при загрузке страницы?

Для меня достаточно предварительно выбрать первый пункт.

enter image description here

Author: Magento Learner, 2017-04-26

3 answers

Предполагая, что вы используете тему rwd, этого также можно достичь, добавив приведенный ниже код jQuery в ваш файл каталог/продукт/представление.phtml.

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery(".configurable-swatch-list li:first-child a").each(function(){
        jQuery(this).children("span").trigger("click");
    });
});
</script>
 6
Author: Jaimin Sutariya, 2017-04-26 12:41:36

Есть два способа, которыми вы можете добиться этого.

Первый способ

1) используйте готовое расширение, Мариус создал одно расширение, вы можете использовать его расширение, и вы можете легко установить предустановленный простой продукт

Https://github.com/tzyganu/Switcher

Второй способ

2) Вы можете выполнить все кодирование самостоятельно для предварительно выбранной опции

Следуйте инструкциям

Ваш config.xml код

<events>
      <catalog_controller_product_init_after>
          <observers>
            <catalog_product_view_init_attribute_selection_by_url>
              <type>model</type>
              <class>yourmodel/observer</class>
              <method>initSelection</method>
            </catalog_product_view_init_attribute_selection_by_url>
          </observers>
      </catalog_controller_product_init_after>
  </events>

И ваш наблюдатель код

public function initSelection(Varien_Event_Observer $observer) {
    $product = $observer->getEvent()->getProduct();
    $controllerAction = $observer->getEvent()->getControllerAction();
    if (Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $product->getTypeId()) {
          $attribute_id = 92; //your attribute_id
          $optionValue  = 102;// attribute option id   
          $productData[$attribute_id] = $optionValue;
          $product->setData('preconfigured_values', new Varien_Object(array('super_attribute'=>$productData))); 
    }
}
 3
Author: Murtuza Zabuawala, 2017-04-26 11:45:46

Попробуйте прототип имитировать

$('foo').simulate('click');

Это вызовет щелчок

Или используйте jQuery

$('#foo').trigger( "click" );

Вот полный код для синего цвета

<script type="text/javascript">

$('attribute92').setValue(27);
var text=jQuery("#attribute92 option:selected").text();
jQuery('#select_label_color').html(text);
jQuery('#option27').addClass("selected");
jQuery('#attribute92').trigger('change');
jQuery(#option27').find("span").trigger('click');
</script>
 2
Author: Qaisar Satti, 2017-04-27 07:22:37