/** * Create an {@link OptionSetField} and {@link NumericField}. * * @param String $name * @param String $title * @param String $value * @param Product|Variation $object Object this stock level is for * @param String $maxLength * @param String $form */ function __construct($name, $title = null, $value = "", $object, $maxLength = null, $form = null) { $quantity = $object->getUnprocessedQuantity(); $cartQuantity = $quantity['InCarts']; $orderQuantity = $quantity['InOrders']; $label = sprintf(_t('StockField', 'Stock : %s are currently in shopping carts, %s in orders that have not been dispatched.'), $cartQuantity, $orderQuantity); $stockChoiceField = new OptionsetField('StockChoice', $label, array(0 => _t('StockField.UNLIMITED', "Unlimited"), 1 => _t('StockField.SPECIFYSTOCK', "Specify Stock"))); $this->stockChoiceField = $stockChoiceField; $stockField = new NumericField('Stock', '', $value, $maxLength, $form); $this->stockLevelField = $stockField; parent::__construct($name, $title, $value, $form); }
function handleUploads() { $upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/uploads/images/"; //$files = CUploadedFile::getInstancesByName('newVariationImage'); //incorrect yii code??? $file = CUploadedFile::getInstanceByName('newVariationImage'); //foreach ($files as $file) { $unique_name = uniqid() . '-' . $file->name; $fileSaved = $file->saveAs($upload_dir . $unique_name); if ($fileSaved) { //save variation $variation = new Variation(); if (is_numeric($_POST['uploadFor']) && $_POST['uploadFor'] > 0) { $variation->variation_id = $_POST['uploadFor']; } $variation->variation_image = $unique_name; $variation->status = 1; if ($variation->variation_id) { $variation->setIsNewRecord(false); } $variation->save(); //link to product $variation_id = $variation->getPrimaryKey(); $product2variation = new Product2variation; if (is_numeric($_POST['uploadFor']) && $_POST['uploadFor'] > 0) { $product2variation->setIsNewRecord(false); } $product2variation->attributes = array( 'product_id' => $_POST['product_id'], 'variation_id' => $variation_id, ); $product2variation->save(); } else { throw new HttpException('File was not saved'); } // } $this->actionUpdate($_POST['product_id']); die(); }
/** * Parses a given experiment. Not meant to be used except for testing. * * @param \stdClass $json the json bit retrieved from the API that represents a experiment. * * @return \Prismic\Variation the manipulable object for that experiment. */ public static function parse(\stdClass $json) { $googleId = isset($json->googleId) ? $json->googleId : 0; $vars = array_map(function ($varJson) { return Variation::parse($varJson); }, $json->variations); return new Experiment($json->id, $googleId, $json->name, $vars); }
public function actionPDF() { $session = new CHttpSession(); $session->open(); if (isset($session['orderVariations']) && is_array($session['orderVariations']) && count($session['orderVariations']) > 0) { require_once Yii::getPathOfAlias('webroot.protected.extensions.pdf.tcpdf') . DIRECTORY_SEPARATOR . 'tcpdf.php'; $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $aOrderVariations = $session['orderVariations']; $html_output = '<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><table>'; $html_output .= '<tr><td colspan="3"></td></tr>'; $html_output .= '<tr><td colspan="3">' . Yii::t('strings', 'Order products:') . "</td></tr>"; $html_output .= '<tr><td colspan="3"></td></tr>'; foreach ($aOrderVariations as $variation_id) { $Product2variation = Product2variation::model()->find('variation_id=' . $variation_id); if (isset($Product2variation)) { $product = ProductDescription::model()->find('product_id=' . $Product2variation['product_id'] . ' AND language_id=' . $this->language_id); $Variation = Variation::model()->find('variation_id=' . $variation_id); $VariationDescription = VariationDescription::model()->find('variation_id=' . $variation_id . ' AND language_id=' . $this->language_id); $html_output .= '<tr><td colspan="3">' . $product['product_name'] . '</td></tr>'; $html_output .= '<tr><td><img src="' . Yii::app()->request->getBaseUrl(true) . '/uploads/images/' . $Variation['variation_image'] . '" alt="product_image" width="100" height="50"/></td>'; $html_output .= '<td>' . $VariationDescription['variation_name'] . '<br/>' . $VariationDescription['variation_description'] . "</td></tr>"; $html_output .= '<tr><td colspan="3"></td><td></td></tr>'; } } $html_output .= '</table></body></html>'; $pdf->SetHeaderData(PDF_HEADER_LOGO, '', '', '', array(0, 64, 255), array(169, 172, 182)); $pdf->setFooterData($tc = array(0, 64, 0), $lc = array(0, 64, 128)); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setLanguageArray($l); $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 14, '', true); $pdf->AddPage(); $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal')); $pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html_output, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = 'L', $autopadding = true); $pdf->Output('order.pdf', 'I'); } }