Лекарство для Magento 1.6.1

Ноябрь 27th, 2011

Патч, чтобы избавить от этого:

http://mytech.dsa.me/2011/11/09/magentocreateentitytablesintegrity-constraint-violation/

http://mytech.dsa.me/2011/11/08/magentocreateentitytables-1170-blobtext-mysql-error/

Применить либо

cd app/code/core/Mage/Eav/Model/Entity
patch Setup.php Setup.php.1.6.1.patch

либо

cd app/code/core/Mage/Eav/Model/Entity
 wget  -O -  http://mytech.dsa.me/wp-content/uploads/2011/11/Setup.php.1.6.1.patch|patch Setup.php

либо

cd app/code/core/Mage/Eav/Model/Entity
 cuel  http://mytech.dsa.me/wp-content/uploads/2011/11/Setup.php.1.6.1.patch|patch Setup.php

Программное добавление опций продукта в Magento

Ноябрь 20th, 2011

protected function makeCustomOption($title, array $optionData, array $values = array())
{
  $defaultData = array(
    'type'			=> 'field',
    'is_require'	=> 0,
    'price'			=> 0,
    'price_type'	=> 'fixed',
    );

  $data = array_merge(
  $defaultData,
  $optionData, array(
/*
В случае если нет метода getProduct(),
то id продукта нужно найти другим способом
*/
    'product_id' 	=> (int)$this->getProduct()->getId(),
    'title'			=> $title
  ));

  $option = Mage::getModel('catalog/product_option')->setData($data);
    foreach($values as $value){
      $value['option_id']=$option->getId();
      $optionValueModel = Mage::getModel('catalog/product_option_value');
      $optionValueModel->setOption($option)->setData($value);
      $option->addValue($optionValueModel);
    }
   return $option;
}

$custom_option=$this->makeCustomOption(
      'Opt 1000',
      array('option_id'=>1000,'type'=>'drop_down','is_require'=>1),
      array(
        array('option_type_id'=>1,'default_title'=>'1111','title'=>'1111','price'=>'15','price_type'=>'fixed'),
        array('option_type_id'=>2,'title'=>'222','price'=>'10','price_type'=>'fixed')));

Magento, отладка загрузки файлов

Ноябрь 18th, 2011

Поиск файла содержащего класс находится в функции Mage/Core/functions.php::mageFindClassFile и, в случае если файл не найден, молча возвращает NULL, который вызовет исключение совсем в другом месте с невнятным сообщением, что такой-то класс не удалось загрузить.

Если при этом отключена отладка, то и это исключение не будет видно, а окончательно сломает выполнение совсем уж невнятное сообщение типа
Call to a member function addToChildGroup() on a non-object in ...app/code/core/Mage/Core/Block/Abstract.php on line 759

В случае когда имя подозрительного класса неизвестно можно включить отладку System->Configuration->Developer->Log settings->Enabled=Yes и посмотреть содержимоеvar/log/exception.log

После этого имя класса преобразовать в имя файла заменой каждого подчеркивания на слеш и добавлением окончания .php и проверить его существование в одном из каталогов core, local или community.

Magento,createEntityTables,Integrity constraint violation

Ноябрь 9th, 2011

Mage/Eav/Model/Entity/Setup.php

Let’s see 1.5.*

CREATE TABLE `{$baseName}_{$type}` (
...
CONSTRAINT `FK_{$baseName}_{$type}` FOREIGN KEY (`entity_id`) REFERENCES `{$base
Name}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE

So, the *_type table reference to the table of the same entinity.

Now, 1.6.0/1.6.1

$mainTable = $connection->newTable($this->getTable($baseTableName))
...
$eavTable->addForeignKey(
 $this->getFkName($eavTableName, 'entity_id', 'eav/entity', 'entity_id'),
 'entity_id', 
 $this->getTable('eav/entity')
...

For some reason now the same column refers to {prefix_}eav_entity but the parent record is inserted into getTable($baseTableName) ie. {resource_eav_table}.

The most most bad this is it is unclear will the Magento move to the only {prefix_}eav_entity for all entities (that has sense) or it is just a bug.

1 2   »