previewData = 'shipping' === $this->data['dummy'] ? $config['shippingPreviewData'] : $config['productPreviewData']; $this->previewData['replacements']['main_product_image_url']['main_product_image_url'] = Variables::$A4B_PLUGIN_BASE_URL . 'assets/img/product-img1.png'; $this->algorithm = $this->data['format']; $this->activeTemplate = new StdClass(); $this->activeTemplate->template = $this->data['template']; } protected function getItems() { $items[] = (object) array('ID' => $this->previewData['ID']); $this->items = $items; } protected function getFileOptions($itemData) { $quantity = 1; return array( 'quantity' => $quantity, 'showName' => $this->showName, 'showLine3' => $this->showLine3, 'showLine4' => $this->showLine4, 'replacements' => $this->getTemplateReplacements($itemData, $this->templateShortcodesArgs), ); } public function getTemplateReplacements($post, $shortcodesArgs) { $replacements = new \ArrayObject(); if (!empty($this->prodListTemplate)) { $replacements[$this->prodListShortcode] = $this->getProdListHtml($post); } foreach ($shortcodesArgs as $shortCode => $args) { $replacements[$shortCode] = $this->getShortcodeFieldValue($post, $args); } return $replacements; } protected function getShortcodeFieldValue($post, $args) { $result = ''; $args['value'] = isset($args['value']) ? $args['value'] : ''; $argsValues = explode('|', $args['value']); foreach ($argsValues as $argsValue) { $text = isset($this->previewData['replacements'][$args['type']][$argsValue]) ? $this->previewData['replacements'][$args['type']][$argsValue] : $args['value']; if (!empty($text)) { $texts[] = $text; $result = implode(' ', $texts); if (!empty($args['before'])) { $result = $args['before'] . $result; } if (!empty($args['after'])) { $result = $result . $args['after']; } break; } } return $result; } protected function getProdListHtml($post) { $prodListHtml = ''; $testProductsNum = preg_match('/test-products=(\d+)/', $this->prodListShortcode, $matches) ? $matches[1] : 1; for ($i = 0; $i < $testProductsNum; $i++) { $productHtml = $this->prodListTemplate; foreach ($this->prodListShortcodesArgs as $shortCode => $args) { $args['qty'] = wp_rand(1, 99); $productHtml = str_replace($shortCode, $this->getShortcodeFieldValue($post, $args), $productHtml); } $prodListHtml .= $productHtml; } return $prodListHtml; } }