'Title'
*
* @since 3.1.0
* @access public
*
* @return array
*/
public function getColumns()
{
$columns = [
'cb' => '',
'image' => '',
'info' => 'Information',
'shipToLocations' => 'Ship to',
'condition' => 'Condition',
'price' => 'Source Price',
'userPrice' => 'Posted Price',
'ship' => 'Shipment Charges',
'curr' => 'Currency'
];
$configurator = ConfiguratorFactory::getConfigurator($this->getType());
$configuratorColumns = $configurator->getColumns();
if ($configuratorColumns) {
$columns = $configuratorColumns;
}
return $columns;
}
/**
* @return mixed
*/
public function getType()
{
return $this->type;
}
/**
* @param mixed $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* @param Product $item
* @return string
*/
public function getId($item)
{
return $this->getType() . '#' . $item->getExternalId();
}
/**
* Prepares the list of items for displaying.
*
* @since 3.1.0
* @access public
*/
public function prepareItems()
{
$_SERVER['REQUEST_URI'] = remove_query_arg(array('reset'), $_SERVER['REQUEST_URI']);
$loader = LoaderFactory::getLoader($this->getType());
$filter = filter_input_array(INPUT_GET);
$current_page = $this->getPagenum();
$data = $loader->loadList($filter, $current_page);
$this->setPagination(array('total_items' => (int)$data['total'], 'per_page' => (int)$data['per_page']));
$this->items = $data['items'];
$importer = AffiliateImporter::getInstance()->getImporter($this->getType());
$db = Db::getInstance()->getDb();
$db->query('delete from ' . $importer->getTableName('goods_archive') . ' where external_id in (
select external_id from ' . $importer->getTableName('goods') . '
)');
$db->query('insert into ' . $importer->getTableName('goods_archive') . '
select * from ' . $importer->getTableName('goods') . '
');
$this->initTable();
}
/**
* @param Product $item
* @return string
*/
public function columnCb($item)
{
return sprintf(
'getPostId() ? ' disabled' : '') . ' value="%s"/>',
$item->getExternalId()
);
}
/**
* @param Product $item
* @return string
*/
public function columnImage($item)
{
return self::putImageEdit($item);
}
/**
* @param Product $product
* @param bool $contentOnly
* @return string
*/
public static function putImageEdit($product, $contentOnly = false)
{
$out = '';
if (!$contentOnly) {
$out .= sprintf('
', $product->getFullId('-'), $product->getImage());
$out .= '[upload image]';
$out .= '
';
}
if ($product->getPhotos() === "#needload#") {
$out .= '
Photos not load yet! Click "load more details"
';
}
$out .= '
Click on an image to select it
';
$out .= '
';
$curImage = $product->getUserImage();
$photos = $product->getAllPhotos();
foreach ($photos as $photo) {
$out .= sprintf(
'
',
$photo
);
}
if (!$contentOnly) {
$out .= '
';
}
return $out;
}
/**
* @param Product $item
* @return string
*/
public function columnInfo($item)
{
$actions = array();
$actions['id'] = 'Product page';
$actions['id'] .= "getSellerUrl() ? "" : "style='display:none'") . ">";
$actions['id'] .= " | Seller page";
$actions['load_more_detail'] = $item->isNeedLoad() ? 'Load more details' : 'Details loaded';
$actions['import'] = $item->getPostId() ? 'Posted' : 'Post to Woocommerce';
if (!$item->getPostId()) {
$actions['schedule_import'] = $item->getUserScheduleTime() ? ("Will be post on " . date("m/d/Y H:i", strtotime($item->getUserScheduleTime()))) . "" : 'Schedule Post';
}
$catName = "";
// foreach ($this->linkСategories as $c) {
// if ($c['term_id'] === $item->link_category_id) {
// $catName = $c['name'];
// break;
// }
// }
$resultData = self::putField($item, "title", true, "edit", "Title", "") .
self::putField($item, 'subtitle', true, "edit", "Subtitle", "subtitle-block") .
self::putField($item, 'keywords', true, "edit", "Keywords", "subtitle-block") .
self::putDescriptionEdit($item) .
($catName ? "Link to category: $catName
" : "") .
$this->rowActions($actions);
return $resultData;
}
/**
* @param Product $product
* @param $field
* @param $edit
* @param string $edit_text
* @param string $lable_text
* @param string $block_class
* @return string
*/
public static function putField($product, $field, $edit, $edit_text = "edit", $lable_text = "", $block_class = "")
{
$value = $product->getField($field);
$loaded = $value !== "#needload#";
$out = '';
if ($value !== "#notuse#") {
$out .= '';
}
return $out;
}
public static function putDescriptionEdit($contentOnly = false)
{
$out = '';
if (!$contentOnly) {
$out .= 'Description: [edit description]';
}
return $out;
}
/**
* @param Product $item
* @return string
*/
public function columnShipToLocations($item)
{
return $item->getCleanAditionalField('ship_to_locations');
}
/**
* @param Product $item
* @return string
*/
public function columnCondition($item)
{
return $item->getCleanAditionalField('condition');
}
/**
* @param Product $item
* @return string
*/
public function columnPrice($item)
{
return self::putField($item, 'price', false);
}
/**
* @param Product $item
* @return string
*/
public function columnUserPrice($item)
{
return self::putField($item, 'user_price', false);
}
/**
* @param Product $item
* @return string
*/
public function columnShip($item)
{
return $item->getCleanAditionalField('ship');
}
/**
* @param Product $item
* @return string
*/
public function columnCurr($item)
{
return self::putField($item, 'curr', false);
}
/**
* @return array
* @override
*/
public function getBulkActions()
{
$actions = array(
'import' => 'Post to Woocommerce (publish)',
'import_draft' => 'Post to Woocommerce (draft)',
'blacklist' => 'Blacklist'
);
return $actions;
}
public function columnOther($item, $columnName)
{
$configurator = ConfiguratorFactory::getConfigurator($this->getType());
if (method_exists($configurator, 'column' . ucfirst($columnName))) {
return $configurator->{'column' . ucfirst($columnName)}($item);
} else {
return '';
}
}
/**
* Get a list of sortable columns. The format is:
* 'internal-name' => 'orderby'
* or
* 'internal-name' => array( 'orderby', true )
*
* The second format will make the initial sorting order be descending
*
* @since 3.1.0
* @access protected
*
* @return array
*/
protected function getSortableColumns()
{
$sortableColumns = [];
$importer = AffiliateImporter::getInstance()->getImporter($this->getType());
return apply_filters($importer->getClassPrefix() . '_get_dashboard_sortable_columns', $sortableColumns);
}
}