/* CUSTOM OPTION CODE */
if
(
strpos
(
$field
,
':'
)!==FALSE &&
strlen
(
$value
)) {
$values
=
explode
(
'|'
,
$value
);
if
(
count
(
$values
)>0) {
@list(
$title
,
$type
,
$is_required
,
$sort_order
) =
explode
(
':'
,
$field
);
$title
= ucfirst(
str_replace
(
'_'
,
' '
,
$title
));
$custom_options
[] =
array
(
'is_delete'
=>0,
'title'
=>
$title
,
'previous_group'
=>
''
,
'previous_type'
=>
''
,
'type'
=>
$type
,
'is_require'
=>
$is_required
,
'sort_order'
=>
$sort_order
,
'values'
=>
array
()
);
foreach
(
$values
as
$v
) {
$parts
=
explode
(
':'
,
$v
);
$title
=
$parts
[0];
if
(
count
(
$parts
)>1) {
$price_type
=
$parts
[1];
}
else
{
$price_type
=
'fixed'
;
}
if
(
count
(
$parts
)>2) {
$price
=
$parts
[2];
}
else
{
$price
=0;
}
if
(
count
(
$parts
)>3) {
$sku
=
$parts
[3];
}
else
{
$sku
=
''
;
}
if
(
count
(
$parts
)>4) {
$sort_order
=
$parts
[4];
}
else
{
$sort_order
= 0;
}
switch
(
$type
) {
case
'file'
:
/* TODO */
break
;
case
'field'
:
case
'area'
:
$custom_options
[
count
(
$custom_options
) - 1][
'max_characters'
] =
$sort_order
;
/* NO BREAK */
case
'date'
:
case
'date_time'
:
case
'time'
:
$custom_options
[
count
(
$custom_options
) - 1][
'price_type'
] =
$price_type
;
$custom_options
[
count
(
$custom_options
) - 1][
'price'
] =
$price
;
$custom_options
[
count
(
$custom_options
) - 1][
'sku'
] =
$sku
;
break
;
case
'drop_down'
:
case
'radio'
:
case
'checkbox'
:
case
'multiple'
:
default
:
$custom_options
[
count
(
$custom_options
) - 1][
'values'
][]=
array
(
'is_delete'
=>0,
'title'
=>
$title
,
'option_type_id'
=>-1,
'price_type'
=>
$price_type
,
'price'
=>
$price
,
'sku'
=>
$sku
,
'sort_order'
=>
$sort_order
,
);
break
;
}
}
}
}
/* END CUSTOM OPTION CODE */
-----------------------------------------------
/* Remove existing custom options attached to the product */
foreach
(
$product
->getOptions()
as
$o
) {
$o
->getValueInstance()->deleteValue(
$o
->getId());
$o
->deletePrices(
$o
->getId());
$o
->deleteTitles(
$o
->getId());
$o
->
delete
();
}
/* Add the custom options specified in the CSV import file */
if
(
count
(
$custom_options
)) {
foreach
(
$custom_options
as
$option
) {
try
{
$opt
= Mage::getModel(
'catalog/product_option'
);
$opt
->setProduct(
$product
);
$opt
->addOption(
$option
);
$opt
->saveOptions();
}
catch
(Exception
$e
) {}
}
}
public
function
parse(Mage_AdminNotification_Model_Inbox
$object
,
array
$data
)
{
$adapter
=
$this
->_getWriteAdapter();
foreach
(
$data
as
$item
) {
$select
=
$adapter
->select()
->from(
$this
->getMainTable())
->where(
'title = ?'
,
$item
[
'title'
]);
if
(
empty
(
$item
[
'url'
])) {
$select
->where(
'url IS NULL'
);
}
else
{
$select
->where(
'url = ?'
,
$item
[
'url'
]);
}
if
(isset(
$item
[
'internal'
])) {
$row
= false;
unset(
$item
[
'internal'
]);
}
else
{
$row
=
$adapter
->fetchRow(
$select
);
}
if
(!
$row
) {
$adapter
->insert(
$this
->getMainTable(),
$item
);
}
}
}
}
public
function
parse(Mage_AdminNotification_Model_Inbox
$object
,
array
$data
)
{
$adapter
=
$this
->_getWriteAdapter();
foreach
(
$data
as
$item
) {
$select
=
$adapter
->select()
->from(
$this
->getMainTable())
->where(
'url=? OR url IS NULL'
,
$item
[
'url'
])
->where(
'title=?'
,
$item
[
'title'
]);
}
if
(isset(
$item
[
'internal'
])) {
$row
= false;
unset(
$item
[
'internal'
]);
}
else
{
$row
=
$adapter
->fetchRow(
$select
);
}
if
(!
$row
) {
$adapter
->insert(
$this
->getMainTable(),
$item
);
}
}
}
This email address is being protected from spambots. You need JavaScript enabled to view it.